How to write SCP success or failure to a file

Does anyone know how to write the results (success and failure) to a file. I am using TCSH on a Solaris machine. I have the following code for a successful SCP...could someone help me add to this so it caputres failures also?

CODE SO FAR (received from a previous post):

scp sourcefile.txt user@targetsystem:/home/test/dir1 && echo "scp done" > out.txt
scp sourcefile.txt user@targetsystem:/home/test/dir1 && echo "scp done"  || echo "fail" > out.txt
1 Like

Thanks for the reply. So, if the targetsystem isn't available or the file doesn't exist...etc then fail will be written to out.txt? Could you explain the code...I'm not an expert, but I figured that the || would only work if scp exits normally.

yes. If the scp command gets succeed then && part scp done will be written to file else failure will be written to the file.

1 Like