PaulC
Occasional Visitor
Here's a little snippet of shell script, intended to go into the services-start script in /jffs/scripts. It scans the USB drive for files having a .cron extension, and for each of those it finds, scans for a comment line containing 'cron:' and uses what follows to register that schedule using cru.
This isn't going to impress the accomplished, but maybe it'll help others.
Here's a simple example: my 'backup-settings.cron' script that backs up my router's settings onto my thumb drive daily:
Note for the security conscious: it's a very bad idea to run scripts automatically from removable media. If your router isn't in a physically secure location, please don't use this technique, or add some signature to .cron files that's unique to your router (that an attacker won't know), and check for it.
This isn't going to impress the accomplished, but maybe it'll help others.
Code:
#
# look for cron scripts on the USB drive, and register them with cru
#
basedir=$(nvram get apps_mounted_path)
if [ -d "${basedir}" ]
then
for file in $(find "${basedir}" -name '*.cron')
do
id=$(basename "${file}" .cron)
schedule=$(sed -n -e '/^#[ \t]*cron:/ {s/^#[ \t]*cron:[ \t]*\(.*\)$/\1/;p}' "${file}")
cru a "${id}" "${schedule} ${file}"
done
fi
Here's a simple example: my 'backup-settings.cron' script that backs up my router's settings onto my thumb drive daily:
Code:
#!/bin/sh
# cron: 07 4 * * *
#
dir=$(dirname "$0")
nvram show > "$dir/settings/nvram-show.txt"
nvram save "$dir/settings/nvram-dump.bin"
cp -a /jffs "$dir/settings/"
Note for the security conscious: it's a very bad idea to run scripts automatically from removable media. If your router isn't in a physically secure location, please don't use this technique, or add some signature to .cron files that's unique to your router (that an attacker won't know), and check for it.