Shell scripting on Advantech routers provides advanced control and automation capabilities for tasks such as remote management, SMS command execution, and network event handling. This is particularly useful for tailoring router behavior to specific needs, including system monitoring, I/O port control, or automating maintenance tasks like scheduled reboots and network interface switching.
Advantech routers, running Linux-based operating systems, typically support shell scripts. These scripts empower administrators to automate routine tasks or implement custom responses to system events. Scripts can be triggered by certain conditions, such as receiving an SMS, establishing a connection, or even regularly scheduled tasks (via cron jobs). Key utilities frequently employed in router shell 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
– "Crucial for network devices, iptables configures firewall rules, NAT, and packet filtering.cron
– Allows scheduling of periodic tasks, such as automatic reboots or monitoring scripts.grep
, awk
, sed
– Standard text processing utilities essential for parsing command outputs or log files.sleep
– For introducing delays in scripts, often used in loops or timed sequences.logger
– For sending messages to the system log (syslog), useful for script debugging and event tracking.For example, this script allows the router to forward incoming SMS messages to an email address. This script, will be called by the SMS daemon upon message receipt. It can be added as a startup script so that the functionality persists after reboots.
# Create the SMS handler script in RAM
cat > /var/scripts/sms << 'EOF'
#!/bin/sh
# Specify email address
EMAIL="john.doe@email.com"
# Forward incoming SMS via email
email -t "$EMAIL" \
-s "Received SMS from $2" \
-m "Authorized: $1, Text: $3 $4 $5 $6 $7 $8 $9"
EOF
To schedule a daily reboot, a cron
job can be added. For example, to reboot daily at 23:55, an entry like 55 23 * * * root /sbin/reboot
would be added to the system's crontab file (/etc/crontab
). Ensure you modify the crontab file correctly to avoid deleting existing jobs. The cron service must then be restarted or signaled to reload its configuration.
This page provides a basic introduction to shell scripting capabilities on Advantech routers. For more comprehensive information, including in-depth theory and practical examples, please refer to our Extending Router Functionality application note. This document delves into various development aspects, such as advanced Shell Scripting techniques, Python programming for router automation, the creation and deployment of Router Apps, and other key development topics.