Bash disaster prevention

From assela Pathirana
Revision as of 00:56, 12 May 2006 by Root (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Like any other versatile tool, consequences of misusing of UNIX scripting can be disasterous. It often helps to save the day

A horror story

You listen to music and have built up a quite extensive library of digital music in your computer under the directory /home/alex/music. Everyday, you copy a folder from under music folder (e.g. beatles/yellowsubmarine) to your MP3 player, which appears as a usb drive (say /mnt/usbstick). You write a small script called loadmusic.bash and save it in /home/alex/,

#!/bin/bash
cd /mnt/usbstick/todaysmusic # Go to the appropriate folder
rm -rf #Delete all the old files 
cp -r /home/alex/music/$1 . 
echo 'Done!'

and call it as

$ loadmusic.bash yellowsubmarine

On one day, you simply forget to insert the usb key, before running the command: