1834461 Members
2983 Online
110067 Solutions
New Discussion

Re: Tar

 
Juno
Occasional Advisor

Tar

I want the tar function to backup, I try to tar a non-existing file , but the system output is still "0" , can suggest what is wrong ? thx.

my tar script is:
tar -cvf /dev/tape /tmp/tar.txt
if [ $? -eq 0 ]
then echo "successful"
else
echo "fail"
fi

but the result is "0" even the file "/tmp/tar.txt" is not existing.
Juno
3 REPLIES 3
Leif Halvarsson_2
Honored Contributor

Re: Tar

Hi,
The /tmp/tar.txt must exist, it is this file you try to backup.

try

tar cvf
Frederic Sevestre
Honored Contributor

Re: Tar

Hi,

I had the same problem with the return code of tar.
A solution is to control the backup using tar -tvf /dev/tape an comparing the output with the list of the expected files.

# find -type f > list.txt
# cat list.txt | sort -u > list.expected
# tar -cvf /dev/tape
# tar -tvf /dev/tape > list.txt
# cat list.txt | sort -u > list.tar
# diff list.expected list.tar

Fr??d??ric


Crime doesn't pay...does that mean that my job is a crime ?
Jose Mosquera
Honored Contributor

Re: Tar

Hi,

This problem is present in my instalation just in 10.20 however in 11.0 works fine, but this is not a tar error because if you put an "echo $?" after tar command you must see return code 5. So the problem is the if value validation, may be needs a cumulative command patch. However I recomend you this routine:

tar -cvf /dev/tape /tmp/tar.txt
STATUS=$?
case $STATUS in
0) echo "Successful"
;;
*) echo "Fail with status: $STATUS"
;;
esac


Rgds.