Коды выхода из TAR задокументируются в «Информация» - используйте информацию TAR
, чтобы прочитать все о смоле. (Вы можете прочитать о «info» с информацией информация
). Похоже, есть 3 (основные) выходные коды. Из информационной документации TAL
:
Possible exit codes of GNU 'tar' are summarized in the following
table:
0
'Successful termination'.
1
'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
file set.
2
'Fatal error'. This means that some fatal, unrecoverable error
occurred.
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::).
Если вы хотели бы получить только сообщение об успехе или неудаче только по вашему выбору, я бы порекомендовал следующее:
tar zcf /home/username/filename.tar.gz -C / var/www/website/ >/dev/null 2>&1
case $? in
0)
printf "Complete Success\n"
;;
1)
printf "Partial Success - some files changed\n"
;;
*)
printf "Disaster - tar exit code $?\n"
;;
esac
Этот вызов TAR-труб как стандартного вывода и ошибка к / dev / null, ака бит ведра. Тогда специальный параметр, $?
, который содержит состояние выхода самого последнего выполненного трубопровода переднего плана, проанализируется оператором
для вывода соответствующего сообщения.