1847686 Members
4396 Online
110265 Solutions
New Discussion

Re: tar error checkng

 
SOLVED
Go to solution
peterchu
Super Advisor

tar error checkng

I want to use tar to backup the files ( tar -cvf ), could suggest how to have the error checking , eg . if the directory is not exist , the backup process is failure , then generate the error message to the log , could suggest what can I do ? thx
3 REPLIES 3
Steven E. Protter
Exalted Contributor
Solution

Re: tar error checkng

tar cvf tarfile.tar *
rc=$?

if [ $rc -ne 0 ] then
echo "error bad tar."
else
echo "good tar"
fi

Add additional code as required.

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hoefnix
Honored Contributor

Re: tar error checkng

Hi,

You can redirect stout and sterr to a logfile
tar cvf .... > outputfile 2 >&1

then check the logfile for errors(grep) and generate some error in your script using "logger". In this way you errors can be in the syslog file or someother you can define in syslog.conf.

HTH,
Peter

Sarvesh A Dhuri
Advisor

Re: tar error checkng

HI

You can simply redirect the output of the tar command to a file by using the ">" symbol and specifying a file name where the output of the tar command will be written

I have been betrayed by our own People