I needed this too - Works in perl - thanks!
#!/usr/bin/perl
`cd /<target-directory>/`;
`scp <userid>\@source.server.com:/<path>/foo . `;
$RC=$?;
if ($RC eq 0){
print "\n good scp with no password\n";
}
else {
print "\nbad scp with no password\n";
}
-----Original Message-----
From: McNeer Mike
[mailto:db2udbdba-ezmlmshield-x39264658.[Email address protected]
Sent: Friday, January 20, 2006 11:25 AM
To: LazyDBA Discussion
Subject: RE: UNIX script checking for FTP
Works like a charm now guys. Thanks for all the help!
Mike
-----Original Message-----
From: Day Daniel
[mailto:db2udbdba-ezmlmshield-x90008782.[Email address protected]
Sent: Friday, January 20, 2006 4:15 AM
To: LazyDBA Discussion
Subject: RE: UNIX script checking for FTP
Looks like you need to separate your two commands with a semi-colon (;),
e.g.
scp *.log [Email address protected]; ret=$?
either that or split it onto 2 lines, e.g.
scp *.log [Email address protected]
ret=$?
To get rid of the second error, surround your variable in double quotes
in
the if statement, e.g.
if [ "$ret" -ne 0 ]; then
this way, the test will have 2 arguments to compare, even if $ret is
empty.
Regards..................Dan
-----Original Message-----
From: McNeer Mike
[mailto:db2udbdba-ezmlmshield-x66160266.[Email address protected]
Sent: 19 January 2006 21:17
To: LazyDBA Discussion
Subject: RE: UNIX script checking for FTP
Ok here is what I am trying. Something is not right I get 2 errors:
ret=0: Not a directory
./transferfilesNONAMEPROD[23]: test: argument expected
Thu Jan 19 15:04:54 CST 2006
cd /backup/servername/repl
scp *.log [Email address protected] ret=$?
if [ $ret -ne 0 ]; then
echo "Error transferring files from SERVERNAME1 to SERVERNAME2" | mailx
-
s "Log transfer Error on ServerA" emailaddresshere.net ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: mail failed with ret=$ret!!!"
fi
exit 2
fi
#cp *.log /backup/servername
rm -f *.log
please let me know what you see wrong here I think I am close.
Thanks for you help!
Mike
-----Original Message-----
From: mireland1
[mailto:db2udbdba-ezmlmshield-x29676682.[Email address protected]
Sent: Wednesday, January 18, 2006 10:48 AM
To: LazyDBA Discussion
Subject: RE: UNIX script checking for FTP
Another 2 cents worth
RC=$?
use cap's to make return code stand out in your code
monty6
-------------- Original message --------------
From: "Kevin" <db2udbdba-ezmlmshield-x86823131.[Email address protected]
> Just a Unix suggestion, avoid using $rc as the variable to hold the
> return code.
>
> Ponder the results if the code was typoed as
>
> rc = $?
>
> This would actually run the startup script rc if it's in your path and
> executable. Not to far fetched.
> Instead, use $ret and
>
> ret=$?
>
> Kevin
>
> -----Original Message-----
> From: ken farmer
> [mailto:db2udbdba-ezmlmshield-x62928304.[Email address protected]
> Sent: Wednesday, January 18, 2006 10:31 AM
> To: LazyDBA Discussion
> Subject: Re: UNIX script checking for FTP
>
> McNeer Mike wrote:
> > I have a very small script that transfers a log file via scp to
> another
> > server. I am in need of a very small piece of code that will give me
> > error checking for successful transfer and ability for email
> > notification if it should fail. This is on Solaris semi latest
version
> I
> > think 2.7? I am very new to the Unix side of things so go easy on me
> > please :-) Any assistance would be appreciated.
>
>
> Mike,
>
> scp should return an error parent if it fails. Here's an example of
> what that would probably look like in korn shell, should be
essentially
> the same in bourne or bash. You could also do it via python, ruby, etc
> - where you'd have cleaner syntax but might have to find the right
> modules to support ssh.
>
> echo " ---------------------------------------------------------"
> echo " send log files to log archive"
> echo " ---------------------------------------------------------"
>
> scp /logdir/myfile.log [Email Address Removed]
> rc=$?
> if [ $rc -ne 0 ]; then
> echo " ERROR: scp failed with rc=$rc"
> mail -s "log archival scp step failed with rc=$rc!" [Email address
> protected]
> rc=$?
> if [ $rc -ne 0 ]; then
> echo "ERROR: mail failed with rc=$rc!!!"
> fi
> exit 2
> fi
>
> A couple of things to note:
>
> If there's a downstream process that is polling for this file, it
might
> pick it up before you've completed sending it. In that case it's
> usually base to send it with a temporary name, then change the name
> after it's complete. Name changing can be done via sftp.
>
> You could also set up this process to poll for an available log file
to
> send. This enables it to be somewhat auto-recovering. However, it will
>
> also need a name-changing step, and this can't be atomic to issue
> mentioned in point #1. So, there's a little bit of complexity there -
> in case one fails and the other succeeds. You would also want to
ensure
>
> that you never got two processes running simultaneously due to some
kind
>
> of hung process- this can be done via simple pid-checking.
>
> Unless you're using a key with a blank passphrase or an ssh-agent
you'll
>
> get prompted for a password. Of the two options the blank passphrase
is
>
> easiest, but the agent method is more secure.
>
>
>
> Regards,
>
> Ken Farmer
>
>
> ---------------------------------------------------------------------
> PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
> website: http://www.LazyDBA.com
> To unsubscribe: http://www.lazydba.com/unsubscribe.html
>
>
>
>
>
> ---------------------------------------------------------------------
> PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
> website: http://www.LazyDBA.com
> To unsubscribe: http://www.lazydba.com/unsubscribe.html
>
---------------------------------------------------------------------
PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
website: http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
---------------------------------------------------------------------
PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
website: http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
******************************************************
The information in this E-mail and in any attachment is
confidential and is intended solely for the addressee.
Access, copying, disclosure or use of such information
by anyone else is unauthorised. If you are not the
intended recipient please contact [Email address protected]
While reasonable efforts are made to ensure these files are free
of virus infection and offensive materials, if something of this
nature is inadvertently sent to you, please destroy it, accept
our apologies and contact [Email address protected] with
details of the sender. We will ensure that action is taken
immediately to prevent any recurrence. Debenhams accept no
responsibility for any views expressed by the originator of this email.
Debenhams Retail plc (reg. no. 83395) Registered in England and Wales.
Registered office: 1 Welbeck Street, London W1G 0AA.
http://www.debenhams.com
******************************************************
---------------------------------------------------------------------
PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
website: http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
---------------------------------------------------------------------
PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
website: http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
DB2 & UDB email list listserv db2-l LazyDBA home page