To improve the user experience on this site we use cookies. I agree | I disagree

Scripting allows advanced control and automation of router tasks, such as remote management, sending SMS commands, and handling network events. It can be useful for customizing router behavior to fit specific needs, whether for monitoring, controlling I/O ports, or automating maintenance tasks like rebooting or switching network interfaces.

Routers running Linux-based operating systems often support shell scripts, which allow administrators to automate tasks or respond to events. Scripts can be triggered by certain conditions, such as receiving an SMS, establishing a connection, or even regularly scheduled tasks (via cron jobs). Common tools in router scripts include:

  • curl – Used to interact with web APIs and perform HTTP actions.
  • io – Manages inputs and outputs for hardware control (e.g., binary inputs/outputs).
  • iptables – Configures network rules and handles firewall operations.
  • cron – Allows scheduling of periodic tasks, such as automatic reboots or monitoring scripts.

For example, this script allows the router to forward incoming SMS messages to an email address. It can be added as a startup script so that the functionality persists after reboots.


EMAIL=john.doe@email.com
cat > /var/scripts/sms << EOF
#!/bin/sh
/usr/bin/email -t $EMAIL -s "Received SMS from $2" -m "Authorized: $1, Text: $3 $4 $5 $6 $7 $8 $9"
EOF

And script below schedules the router to automatically reboot daily at a specific time (e.g., 23:55). It's useful for maintaining performance and ensuring stable operations over time.


echo "55 23 * * * root /sbin/reboot" > /etc/crontab
service cron start


More examples can be found in our Support FAQ section. For example 
Remote upload of firmware, User Module, configuration via script or
How can I expand port forwarding?

And even more examples and advanced use cases can be found in the Extending Router Functionality application note. This document covers topics like handling SMS commands, switching between network interfaces, and sending SNMP traps.