найдите: как не иметь ошибки (stderr), когда никакие файлы не существуют

выполненный:

rsync -avz user@remoteMachine:/home/user/public_html /home/user/public_html 
1
задан 24 September 2013 в 01:13
2 ответа

Попробуйте это

#redirect stderr to null
exec 2> /dev/null
FILECOUNT = `find *.log -mtime +1|wc -l`

#redirection of stderr to file
exec 2> /tmp/errors.txt

# gzip old log files    
if [ $FILECOUNT != '0' ]; then
   find *.log -mtime +1|xargs gzip -f
fi

# test if error log file is empty
if [ -s /tmp/errors.txt ]; then
    .....
fi`
1
ответ дан 3 December 2019 в 21:26

Если вы используете GNU-версию xargs, вы можете использовать -r :

   --no-run-if-empty
   -r     If the standard input does not contain any nonblanks, do not run
          the command.  Normally, the command is run once even if there is
          no input.  This option is a GNU extension.

Код:

# redirection of stderr to file
exec 2> /tmp/errors.txt

# gzip old log files
find *.log -mtime +1|xargs -r gzip -f

# test if error log file is empty
if [ -s /tmp/errors.txt ]; then
    .....
fi
1
ответ дан 3 December 2019 в 21:26

Теги

Похожие вопросы