Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
日志记录unix“;cp";(复制)命令响应_Unix_Logging_Command_Cp - Fatal编程技术网

日志记录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