How to write SCP success or failure to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write SCP success or failure to a file
# 1  
Old 03-18-2012
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):
Code:
scp sourcefile.txt user@targetsystem:/home/test/dir1 && echo "scp done" > out.txt


Last edited by jim mcnamara; 03-18-2012 at 12:11 AM.. Reason: code tags
# 2  
Old 03-18-2012
Code:
scp sourcefile.txt user@targetsystem:/home/test/dir1 && echo "scp done"  || echo "fail" > out.txt

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-18-2012
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.
# 4  
Old 03-18-2012
yes. If the scp command gets succeed then && part scp done will be written to file else failure will be written to the file.
This User Gave Thanks to pandeesh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to execute Oracle procedure and trigerring email on success and failure

Here is the shell script which need to trigger a stored procedure and when the record count is 0 then it should capture in the log that 0 duplicate records are found and if it's more than 0 then log with no of records. Also if there is any sqlerror then it should write the same in the log file and... (17 Replies)
Discussion started by: senmng
17 Replies

2. UNIX for Advanced & Expert Users

Executing a job with file success

Hello All, I have a scenario where I need suggestion I am creating a file watcher job on autosys and and command job to do a SCP a file from one server to another. My file watcher will get success once the file get receive. The file I am receiving a zip file. THe command job which I am... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

3. Red Hat

Fedora 19 "useradd" failure, GUI success

Hey guys/gals, I have a Fedora 19 box with a 26TB RAID set mounted as my home directory # mount|grep home /dev/md0 on /home type xfs (rw,relatime,seclabel,attr2,inode64,logbsize=128k,sunit=256,swidth=3584,noquota) I have been able to add/modify user accounts using VNC +... (4 Replies)
Discussion started by: jjinno
4 Replies

4. Shell Programming and Scripting

Success/failure status of telnet connection

Hi, I am running a shell script which will spawn the telnet and login. But sometimes, the telnet session itself is not getting spawned. My requirement is, if the telnet session is not spawned, the user must be notified that it failed. Is there any command to capture the status of telnet... (2 Replies)
Discussion started by: merin
2 Replies

5. Shell Programming and Scripting

Automating telnet checking for success/failure

Hi I wanna automate the telnet process for port connection.. # telnet 0 port_number Trying 0.0.0.0... Connected to 0. Escape character is '^]'. If its connected how to make it disconnect automatically.. And how to check for success or failure.. (0 Replies)
Discussion started by: ningy
0 Replies

6. SCO

file system not getting mounted in read write mode after system power failure

After System power get failed File system is not getting mounted in read- write mode (1 Reply)
Discussion started by: gtkpmbpl
1 Replies

7. Shell Programming and Scripting

to write the logs of scp

Hi Unix gurus, I created this script to automate the copying of files daily from one server to another using the scp command. --> #!/bin/ksh KEY="$HOME/.ssh/SSHKEY" if ;then echo "Private key not found at $KEY" >> $LOGFILE echo "* Please create it with \"ssh-keygen -t dsa\" *" >>... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

8. Shell Programming and Scripting

how to exit with success if the file is not found

I want to put a exit if there is no file found. In the directory I can have multiple txt files with EPISGCHGS as prefix or maynot have one. When I am trying the following it is erroring if there is no text file with the EPISGCHGS as prefix. for file in EPISGCHGS*.txt do cat $file >... (2 Replies)
Discussion started by: apps_user
2 Replies

9. UNIX for Advanced & Expert Users

Capturing sendmail success/failure?

I am working on a project that will use sendmail to send reports form a shell script. Since these reports are very important and go out at all times of the day, I need to be able to capture if sendmail is unsuccessful or errors out. The emails may have multiple recipients with multiple attachments.... (2 Replies)
Discussion started by: ssracer
2 Replies

10. Shell Programming and Scripting

Determining the failure or success of FTP

Hi there, I am in the process of writing a shell script to transfer files to a remote directory. Is there a method to determine the success or the failure of the ftp process. Regards Jim (4 Replies)
Discussion started by: JimJim
4 Replies
Login or Register to Ask a Question