Forum Moderators: coopster & phranque

Message Too Old, No Replies

SCP file management script

Need help with error scp codes

         

wskibum

6:47 am on Mar 16, 2008 (gmt 0)

10+ Year Member



Hi all,
I am a newbie at Perl, nuf said there I guess.

I have a need to move my log files around and I am using a simple perl scp script to do this. Now I need to add some error reporting to the script and I am in over my head.

1: I need to send an email when scp cannot connect to a server
2: I need to send and email if scp cannot find the file to download

How can I get the error codes on a failure and what do I do with it?

Please help me out if you can, I've been searching the web with no luck for 2 days.

currently my scp command looks something like this:

GET THE FILE WITH SCP
#

$filetoget="$LOGFILEDIR/$f\.@FILEDOMAIN\$i\.$year-$mon-$mday";

$command = "/usr/bin/scp $a:$filetoget $f\.@FILEDOMAIN\$i\.$year$mon$mday\.$a";

DrDoc

6:55 am on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

A shot in the dark ... but I assume the

scp
man page will be a good place to start.

[edited by: DrDoc at 6:55 am (utc) on Mar. 16, 2008]

wskibum

7:17 am on Mar 16, 2008 (gmt 0)

10+ Year Member



I know you will be stunned but I've already done that.

phranque

7:33 am on Mar 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], wskibum!

try testing and/or outputting the $! variable and see what you get.
you can print it in numeric or string context to see either the error number or the error string.

wskibum

7:51 am on Mar 16, 2008 (gmt 0)

10+ Year Member



That sounds encouraging, how do I do that?

phranque

7:55 am on Mar 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



print "error message:$!" if $!;

DrDoc

4:33 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I think it is
$?
you need to check ...

scp exits with 0 on success or >0 if an error occurred.

These are the only ones I was able to find:
1: General error in file copy
2: Destination is not directory, but it should be
3: Maximum symlink level exceeded
4: Connecting to host failed
5: Conneciton broken
6: File does not exist
7: No permission to access file
8: General error in sftp protocol
9: File transfer protocol mismatch
10: No file matches a given critera
65: Host not allowed to connect
66: General error in ssh protocol
67: Key exchange failed
68: Reserved
69: MAC error
70: Compression error
71: Service not available
72: Protocol version no supported
73: Host key not verifiable
74: Connection failed
75: Disconnected by application
76: Too many connections
77: Authentication cancelled by user
78: No more authentication methods available
79: Invalid user name