日志记录unix“;cp";(复制)命令响应
我正在处理一些文件,因此,结果可能是任何一种方式 例如:日志记录unix“;cp";(复制)命令响应,unix,logging,command,cp,Unix,Logging,Command,Cp,我正在处理一些文件,因此,结果可能是任何一种方式 例如: >cp-R bin/*.ksh../backup/ >cp-bin/file.sh../backup/bin/ 当我执行上述命令时,它会被复制。如果复制成功,则系统没有响应。如果没有,则在终端本身中打印错误或响应cp:file.sh:没有这样的文件或目录 现在,我想记录错误消息,或者如果成功,我想将自定义消息记录到一个文件中。我该怎么办 真是帮不上忙 谢谢尝试在shell脚本中编写以下内容: #these three lines are
>cp-R bin/*.ksh../backup/
>cp-bin/file.sh../backup/bin/
当我执行上述命令时,它会被复制。如果复制成功,则系统没有响应。如果没有,则在终端本身中打印错误或响应cp:file.sh:没有这样的文件或目录
现在,我想记录错误消息,或者如果成功,我想将自定义消息记录到一个文件中。我该怎么办
真是帮不上忙
谢谢尝试在shell脚本中编写以下内容:
#these three lines are to check if script is already running.
#got this from some site don't remember :(
ME=`basename "$0"`;
LCK="./${ME}.LCK";
exec 8>$LCK;
LOGFILE=~/mycp.log
if flock -n -x 8; then
# 2>&1 will redirect any error or other output to $LOGFILE
cp -R bin/*.ksh ../backup/ >> $LOGFILE 2>&1
# $? is shell variable that contains outcome of last ran command
# cp will return 0 if there was no error
if [$? -eq 0]; then
echo 'copied succesfully' >> $LOGFILE
fi
fi