capturing exceptions from an scp clause | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

capturing exceptions from an scp clause

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-24-2012
guessingo guessingo is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 30 March 2014, 10:18 PM EDT
Posts: 55
Thanks: 1
Thanked 0 Times in 0 Posts
capturing exceptions from an scp clause

hpunix

I have a script, that will scp -p a file. The server has keys set up. So I don't even pass a username.

scp -p filename server:/directory

There is a small chance that I can get an error. could be networking, etc... this is run from a job. I like to capture all exceptions when I do this.

I can do
if { $? - eq 1 ]; then Log a message.

how would I capture the exception in a scp clause?
Sponsored Links
    #2  
Old 02-24-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 September 2014, 8:11 PM EDT
Location: Saskatchewan
Posts: 19,390
Thanks: 790
Thanked 3,270 Times in 3,065 Posts
You don't need to use $? when checking a command's return value. You can check the command directly.


Code:
if ! scp source destination
then
        echo "something bad happened" >&2
fi

Or even
Code:
scp source destination || echo "something bad happened" >&2

If anything goes wrong, it will likely print an error to standard error. If you redirect standard error into a logfile yourself before you run it, all error messages will go into it.


Code:
exec 2>path/to/logfile

touch / # Since you're not root, this should print 'permission denied' into logfile

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Relationship between exceptions and signals manolo123 Programming 0 01-11-2012 03:50 PM
Diff with exceptions Question Smitty0881 UNIX for Dummies Questions & Answers 3 01-05-2012 10:51 PM
java Exceptions color ramse8pc UNIX for Advanced & Expert Users 0 07-27-2011 11:55 AM
Remove directory with exceptions zivsegal UNIX for Advanced & Expert Users 1 11-30-2009 11:44 AM
exceptions in import madmat Shell Programming and Scripting 1 07-12-2007 03:38 PM



All times are GMT -4. The time now is 06:06 AM.