The tar exit codes are documented in the "info" manual - use
info tar to read all about tar. (You can read about "info" with
info info). It seems there are 3 (major) exit codes. From the
info tar documentation:
Possible exit codes of GNU 'tar' are summarized in the following
'Some files differ'. If tar was invoked with '--compare'
('--diff', '-d') command line option, this means that some files in
the archive differ from their disk counterparts (*note compare::).
If tar was given '--create', '--append' or '--update' option, this
exit code means that some files were changed while being archived
and so the resulting archive does not contain the exact copy of the
'Fatal error'. This means that some fatal, unrecoverable error
If 'tar' has invoked a subprocess and that subprocess exited with a
nonzero exit code, 'tar' exits with that code as well. This can happen,
for example, if 'tar' was given some compression option (*note gzip::)
and the external compressor program failed. Another example is 'rmt'
failure during backup to the remote device (*note Remote Tape Server::).
If you would like to only have a success or failure message of your choice, I'd recommend the following:
tar zcf /home/username/filename.tar.gz -C / var/www/website/ >/dev/null 2>&1
case $? in
printf "Complete Success\n"
printf "Partial Success - some files changed\n"
printf "Disaster - tar exit code $?\n"
This invocation of tar pipes both the standard output and error to /dev/null, a.k.a. the bit bucket. Then the special parameter,
$?, which holds the exit status of the most recently executed foreground pipeline, is parsed by the
case statement to output the relevant message.
v) option if verbose is not what you want? If it fails for any reason it will still output an error message which you'll get by email so you'll know about the problem.