#!/bin/sh
#
umask 022
myscript=$(basename $0 | cut -f 1 -d'.')
exec > ${myscript}.log 2>&1
#
mydatestring=`date +%Y_%m_%d_%H%M`
myskydir="/tmp/mnt/ent/skynet"
myentdir="/tmp/mnt/ent/entware"
mydivdir=${myentdir}/share/diversion/list
mypixdir=${myentdir}/var/cache/pixelserv
mystbcnf=${myentdir}/etc/stubby/stubby.yml
mycronuser="root"
mybackupdir="/tmp/mnt/smb/share/backup"
myfiledir=${mybackupdir}/file
mynvramdir=${mybackupdir}/nvram
mydbdir=${mybackupdir}/db
mylogdir=${mybackupdir}/log
#
mkdir ${mybackupdir}/file/${mydatestring}
find ${mybackupdir}/file -maxdepth 1 -type f -exec mv {} ${mybackupdir}/file/${mydatestring} \;
for myfile in ${mydivdir}/blacklist ${mypixdir}/ca.crt ${mypixdir}/ca.key /jffs/nvram/dhcp_hostnames /jffs/scripts/dnsmasq.postconf /jffs/scripts/firewall-start /jffs/configs/fstab /jffs/scripts/log-dhcp.sh /jffs/addons/ntpmerlin.d/ntp.conf /jffs/configs/profile.add /jffs/scripts/wan-start ${mydivdir}/wc_blacklist ${mydivdir}/whitelist /var/spool/cron/crontabs/${mycronuser}
do
echo "==============================================================================================="
ls -la ${myfile}
cp ${myfile} ${myfiledir}
echo "#"
echo "Copied ${myfile} to ${myfiledir}"
myname=`basename ${myfile}`
/opt/bin/cksum ${mybackupdir}/file/${mydatestring}/${myname}
/opt/bin/cksum ${mybackupdir}/file/${myname}
diff ${mybackupdir}/file/${mydatestring}/${myname} ${mybackupdir}/file/${myname}
done
/opt/bin/firewall stats search manualbans > ${myfiledir}/skynet_manual_bans.txt
#
mkdir ${mybackupdir}/nvram/${mydatestring}
find ${mybackupdir}/nvram -maxdepth 1 -type f -exec mv {} ${mybackupdir}/nvram/${mydatestring} \;
for mynvram in custom_clientlist dhcp_staticlist dns_probe_content ntp_server0 ntp_server1 sshd_authkeys
do
echo "==============================================================================================="
nvram get ${mynvram}
nvram get ${mynvram} > ${mynvramdir}/${mynvram}
echo "#"
echo "Backed up nvram variable ${mynvram} to ${mynvramdir}/${mynvram}"
/opt/bin/cksum ${mybackupdir}/nvram/${mydatestring}/${mynvram}
/opt/bin/cksum ${mybackupdir}/nvram/${mynvram}
diff ${mybackupdir}/nvram/${mydatestring}/${mynvram} ${mybackupdir}/nvram/${mynvram}
done
nvram getall > ${mynvramdir}/nvram_getall
#
mkdir ${mybackupdir}/db/${mydatestring}
find ${mybackupdir}/db -maxdepth 1 -type f -exec mv {} ${mybackupdir}/db/${mydatestring} \;
for mydb in /jffs/.sys/TrafficAnalyzer/TrafficAnalyzer.db /jffs/.sys/nc/nt_center.db /tmp/db/visdata.db /tmp/mnt/ent/traffic/tomato_rstats_0c9d9201f098.gz /var/lib/misc/rstats-history.gz /var/lib/misc/rstats-speed.gz
do
echo "==============================================================================================="
ls -la ${mydb}
cp ${mydb} ${mydbdir}
echo "#"
echo "Copied ${mydb} to ${mydbdir}"
myname=`basename ${mydb}`
done
#
mkdir ${mybackupdir}/log/${mydatestring}
find ${mybackupdir}/log -maxdepth 1 -type f -exec mv {} ${mybackupdir}/log/${mydatestring} \;
for mylog in /tmp/syslog.log /opt/var/log/dnsmasq.log /jffs/amtm-disk-check.log /tmp/log-dhcp.sh.log
do
echo "==============================================================================================="
ls -la ${mylog}
cp ${mylog} ${mylogdir}
echo "#"
echo "Copied ${mylog} to ${mylogdir}"
myname=`basename ${mylog}`
chmod 644 ${mylogdir}/${myname}
done
echo "==============================================================================================="
#
Well stated. I will use a statement like this when someone asks whether he/she should switch from stock ASUS firmware. The benefit really depends on the knowledge/skills of the user. Most casual users want an appliance that just "works" with little user participation.On the other hand, one must consider whether Merlin is right for you based on your knowledge and skills.
Agreed. But it is only fair to also inform them of the effort involved in learning. It's not just plug-and-play. They'll need to expend a good deal of effort and initiative.And, on the other hand, someone who is asking to learn should be encouraged, no matter their current skill level too.
https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts1) Load the script up (using putty and WINSCP as needed) but I don't know the file structures on where the scripts get loaded, naming of scripts, etc.).
https://github.com/RMerl/asuswrt-merlin/wiki/Scheduled-tasks-(cron-jobs)2) Once I get script loaded to router, I want to create a cron job that will run the script every x minutes (say every 15 minutes)
#!/bin/sh
cru a myscript "*/2 * * * * /jffs/scripts/something.sh"
Thanks, I'll review these in more detail when I have time. Just a general question, do scripts have a naming structure as "namescript.sh"?
Hope this helps get you down the learning path.
The vi installed (at least with the ASUS firmware) seems to be stripped-down compared to what I'm used to using.So there are some things I've had to learn not to do. I'm not aware of any other file editor native to the router. If so, what else is there?
Unfortunately nano (and a whole bunch of other commands) is missing in the OEM ASUS firmware.
I happen to have entware, so I downloaded and use a full version of vi. I just need to remember to invoke it with "vim".If you are developing scripts, I highly recommend learning how to edit them on the router. It gets very cumbersome editing then copying them from your PC, running chmod to make them executable, etc.
I've used vi for so many years that it is second-nature. In fact, on my PC sometimes forget when using a full-screen editor (like Word or Notes) and type 'i' or 'a' before typing. And I find myself ending by hitting the <ESC> key. I often find I've entered ESC:wq when I'm finished and want to save the file and exit
The vi installed (at least with the ASUS firmware) seems to be stripped-down compared to what I'm used to using.So there are some things I've had to learn not to do. I'm not aware of any other file editor native to the router. If so, what else is there?
Anyway, I highly recommend learning how to use the native editor(s) instead of copying scripts - especially during the debugging phase.
Update: ooops - had to edit to remove an extraneous 'i'
Or vi users are showing their age ;-)Theres also nano. Its personal preference really, some like vi some like nano.
Most coders/scripters prefer vi as it requires using a key to begin editing where as a key slip in nano could go un-noticed and ruin your code.
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!