July 2, 2009

Check your IP periodically with a small shell script

For those who are subject to dynamically assigned DSL IP, you would probably be familiar with a site such as http://myip.dk Here is a small script I use to fetch my public IP for other script processes updated “due to changes on the site myip.dk, I rewrote the script” #!/bin/bash link=lynx -dump -listonly 'http://myip.dk' | awk -F: '/myip.dk/ && $0 != "" { getline; print $0}' | awk -F " " {'print $2'} curl -s $link | grep ‘“Box”’ | egrep -o ‘[0-9. ... Read more

October 22, 2008

Quick Script to monitor a process

There are numerous programs such as monit which are widely used as to monitor processes and take certain actions in case of different events. Here is a little tip as to quickly monitor an service/process if you aren’t wanting to go through the hassle to configure monit #!/bin/bash r=$(ps cax |grep -c NAME_PROCESS) if [ $r -eq 0 ]; then service NAME_PROCESS restart echo “NAME_PROCESS has crashed” | mail -s “monitoring SERVERID” your_Email_Address fi ... Read more

October 11, 2008

Delete empty files, older than x days

Q: How do I delete files that older than a certain amount of days and which are empty A: find . -empty -type f -mmtime +X| xargs rm or for those fancing exec, use find . -empty -type f -mmtime +X -exec rm {} ** X must be replaced with the number of days cheers,