Hi All,
I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully.
After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status returned is for the entire operation i.e for find + tar. But what i want is only the status of the tar command.
can anyone help me with this.
#!/bin/sh
find . -name '*.txt' -print | tar -czf save1.tgz --files-from - > /dev/null 2>&1
RC=$?
if [ $RC -gt 0 ] ; then
echo " tar operation failed with $RC "
else
echo " tar operation passed with $RC "
fi
My bad, actually question is i am getting a incorrect return status from the entire command.
lets change the above find+tar to
find ./abc -name '*.txt' -print | tar -czf save1.tgz --files-from - > /dev/null 2>&1
RC=$?
if [ $RC -gt 0 ] ; then
echo " tar operation failed with $RC "
else
echo " tar operation passed with $RC "
fi
paddu:/tmp/pradeep # ls abc
/bin/ls: prg: No such file or directory
paddu:/tmp/pradeep # ./a.sh
find: ./abc: No such file or directory
tar operation passed with 0
Here the return status is 0 even the directory required doesnot exists.
How to get the correct status here