Friday, August 15, 2008

Best Bash Script EVER - "Just In Case"

clayg@m-net:~$ cat bin/jic
if [ $# -eq 0 ]
echo "usage: jic [filename]"
exit 1
if ! [ -e $1 ]
echo "$1 does not exist!"
exit 1
ext=$(date +%y%m%d.%H%M%S)
cp $1 $jic
chmod -x $jic
echo "SAVED: $jic"

Credit goes to a sourpuss I used to work with by the name of Chuck Carson, who gave me the idea. Where ever you are big guy - thanks.

The script creates a backup copy of a file you are about to modify:
# jic /etc/sysconfig/iptables
would create a copy called /etc/sysconfig/iptables.YYMMDD.HHMMSS

you know... just in case

Also handy for versioning revisions to scripts you're working on - never now when you're latest hack will turn out to be a total bust.

Also - go get yourself a free shell account on