From: Tim Hunter Date: 2008-10-18T09:00:14+09:00 Subject: Re: Error Exception if script doesn't run jackster the jackle wrote: > It seems to work but not for this command, perhaps since scp gets > executed (but does not complete) the system variable is not false? > > [code] > `scp -i /home/jsmith/.ssh/id_rsa /files*.tar jsmith@172.20.1.1:` > [/code] > > The error code I get when I run the script manually is as follows > because 172.20.1.1 is no longer on the network: > > ssh: connect to host 172.20.1.1 port 22: No route to host > lost connection > > I was hoping the system variable would trip when this command fails? > > jack In the general case, when a command succeeds it returns 0 and when it fails it returns something else. However, this is a convention, not a rule. It is entirely possible for a command to fail and still return 0. If so, you can't determine if it fails by simply checking the return code. I have no idea whether or not scp returns non-0 on failure. You can check by running it yourself in a shell. Immediately after it fails enter 'echo $?'. This will show you the exit status. For example: ~$ ls test.rb test.rb ~$ echo $? 0 ~$ ls nothere ls: nothere: No such file or directory ~$ echo $? 1 If your scp command returns 0 in this case then the only way to detect that it failed is to inspect the message, which it probably is writing to stderr. More information about exit status and $? can be found on the Internet. -- RMagick: http://rmagick.rubyforge.org/