I try get standard error communicate from mkdir -p $FINAL_BACKUP_DIR
and send in message by logger
.
It make log more complete for example the user will be know he do not have permission or $FINAL_BACKUP_DIR
does not exists.
if ! mkdir -p $FINAL_BACKUP_DIR; then
logger -t $LOGGER_TAG "Cannot create backup directory in $FINAL_BACKUP_DIR. Standard error communicate. Backup canceling." 1>&2
exit 1;
fi;
I try something like that:
if ! mkdir -p $FINAL_BACKUP_DIR 2>> ${test1}; then
logger -t $LOGGER_TAG "Cannot create backup directory in $FINAL_BACKUP_DIR. Backup canceling. $test1" 1>&2
exit 1;
fi;
But this solution does not working for me in two ways. When I create test1
earlier test1=0
or without that.
I work with Ubuntu 14.04.
/dev/null
is the standard device to "throw things away".
So
some_command 2> /dev/null
will send the errors from some_command
to /dev/null
- ie throw away the errors.
Thus:
if ! mkdir -p $FINAL_BACKUP_DIR 2> /dev/null
then
logger -t $LOGGER_TAG "Cannot create backup directory in $FINAL_BACKUP_DIR. Backup canceling."
exit 1
fi
Note that you also didn't need all those extra ;
characters :-)
EDIT:
You can also direct error to output and capture the result in a variable and test if that variable is empty. In this way you can report on the reason to the user
result=$(mkdir -p $FINAL_BACKUP_DIR 2>&1)
if [ -n "$result" ]
then
logger -t $LOGGER_TAG "Cannot create backup directory in $FINAL_BACKUP_DIR. Backup canceling: $result"
exit 1
fi
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments