Sunday, September 28, 2008


(Yes, yet another shell script)
I wrote a little bash script to replace all the underscores in a filename with spaces, in the current directory.
Here it is:

#this script renames all filenames containing _ with [space], in the current directory
#copy to /usr/local/bin and set permission as +x

total=`ls | grep .*_.* | wc -l`
while [ $count -lt $total ]

filename=`ls | grep .*_.* | head -1`
newfilename=`ls | grep .*_.* | head -1 | tr '_' ' '`
mv "$filename" "$newfilename"
echo "renamed $filename to $newfilename"
count=`expr $count + 1`

Friday, September 12, 2008

Alternate approach to 'keeponline'

Instead of running the 'keeponline' script (described here) as a cron job, I decided to make it run as a standalone script. (Because the cron job kept spamming my syslog file)

The new /usr/local/bin/ looks like this:

echo "Going Online..."
/usr/local/bin/ > /dev/null
while true; do
ping -c 1 -W 120 > /dev/null

if [ "$?" = "0" ]; then
echo "You are connected"
/usr/local/bin/ > /dev/null
echo "Disconnect detected at `date`, reconnecting" >> /home/akudewan/logs/keeponline.log
sleep 10m

Next I make another script, keeponline-launch inside /etc/network/if-up.d/


# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

sh /usr/local/bin/ &

exit 0

This will basically launch the keeponline script when the network interface comes up :)

(Thanks to Vivaldi Gloria from ubuntuforums)