View Single Post
  #4  
Old 4th February 2008, 17:48
topdog topdog is offline
Senior Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 1,352
Thanks: 0
Thanked 153 Times in 150 Posts
Default

Quote:
Originally Posted by anything
thank you, but can you add a massage inform that the backup is successfully created, when it do. and please could you give me a little explanation of it, I am really beginner on it. I need to understand the code.

thanks
Comments are inline
Code:
#!/bin/bash
#
# Andrew <andrew@topdog.za.net>
# Quick dirty script to backup a file
# 03-02-2008
#

#check if any option was passed or --help
if [[ "$1" = "" || "$1" = "--help" ]]; then
        echo " Usage: $0 <file to backup>"
        echo ""
        exit 1
fi

#check if file exists
if [ ! -r $1 ]; then
        echo "The file $1 does not exist"
        echo ""
        exit 1
fi
#work around for systems with cp -i alias
aliased=0
j=$(alias | grep cp &>/dev/null)
if [ "$?" = "0" ]; then
        i=$(alias cp | grep '\-i' &>/dev/null)
        if [ "$?" = "0" ]; then
                aliased=1
                unalias cp
        fi
fi
# actual copy
cp -a $1 $1.bak
if [ "$?" = "0" ]; then
        echo "The file $1 has been backed up !"
fi

#set alias back
if [ $aliased = "1" ]; then
        alias cp='cp -i'
fi
__________________
----
http://www.topdog.za.net - Got Linux problems ? - I can help.
http://www.baruwa.org - Try it.
Reply With Quote