2011-07-11 8 views
0

私はいくつかのファイルに対処しているので、結果はどちらかの方法になります。logging unix "cp"(copy)コマンドの応答

例えば:私は上記のコマンドを実行すると、そのコピーを取得

>cp -R bin/*.ksh ../backup/

>cp bin/file.sh ../backup/bin/

。正常にコピーされた場合、システムからの応答はありません。そうでない場合は、エラーまたは応答を端末自身cp: file.sh: No such file or directoryに出力します。

エラーメッセージを記録するか、正常に終了した場合はカスタムメッセージをファイルに記録します。どのようにできるのか?

本当に助けてください。

おかげ

答えて

2

シェルスクリプトでこれを書いてみてください:

#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 
+0

おかげでたくさん:))私が望んでいます –

関連する問題