- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to setup an email alert notification for f...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 06:23 AM
тАО04-28-2009 06:23 AM
My DBA setup a sftp cron job to upload data to a remote sftp server. How to setup an email alert notification for failed SFTP jobs? so my DBA can resend the data transfer. Can you please help? Thank you.
Regards,
Jan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 06:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 06:57 AM
тАО04-28-2009 06:57 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Thanks for the reply. I asked my DBA if her sftp script returns zero and non-zero for job status. DBA isn't sure, but she shows me the sftp log, it has only the verbes of the sftp connection. I think by default a script always return zero or non-zero for its result, right? Is there a way to test it?
Thanks.
Regards,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 07:43 AM
тАО04-28-2009 07:43 AM
Re: How to setup an email alert notification for failed SFTP jobs?
testing via the command line, and "echo $?" will show 0 regardless, you can prove this by trying to copy an non-existent file on the command line. the "script" will have to be written such that it scans to output log or takes some other action to confirm the file transfered completely / successfully. based on that action, the script should then return a zero or non-zero exit code.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 07:48 AM
тАО04-28-2009 07:48 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Thanks for the information. I will let my DBA test this. Please wait for my update soon. Thanks again.
Regards,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:02 AM
тАО04-28-2009 08:02 AM
Re: How to setup an email alert notification for failed SFTP jobs?
As OldSchool notes, the return value of (S)FTP isn't going to help. You need to capture the session dialog in a file and parse it for success or failure.
If, however, your (S)FTP script were written in Perl, the Perl module implementations allow simple tests like:
...
$sftp->put( $localfile, $remotefile );
if ( $sftp->error ) {
warn "Can't put '$localfile' -> '$remotefile': " . $sftp->error . "\n";
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:08 AM
тАО04-28-2009 08:08 AM
Re: How to setup an email alert notification for failed SFTP jobs?
I will check with my DBA if their sftp script is in Perl or not. I will search this forum website and hopefully I can find some sample sftp scripts in this forum website.
Thanks again.
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:43 AM
тАО04-28-2009 08:43 AM
Re: How to setup an email alert notification for failed SFTP jobs?
You could go as simple as this:
If the sftp job fails send an email.
If its a shell script.
sftp or scp command ...
rc=$?
#This gets you the return code.
if [ $rc -ne 0 ]
then
echo "File transfer error" | mailx -s "subject" email@yuor.net
fi
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:49 AM
тАО04-28-2009 08:49 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Thanks a lot, I will try this too. Please wait for my update.
Have a nice day.
Regards,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:56 AM
тАО04-28-2009 08:56 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Re-read OldShool's post. A simple return code from SFTP in a shell script is _not_ going to work:
Consider:
# cat ./mysh
#!/usr/bin/sh
sftp somehost << EOF!
get /no/file /tmp/nofile
quit
EOF!
RC=$?
echo "rc=${RC}"
# ./mysh
Connecting to somehost...
sftp> get /no/file /tmp/nofile
Couldn't stat remote file: No such file or directory
File "/no/file" not found.
sftp> quit
rc=0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:07 AM
тАО04-28-2009 09:07 AM
Re: How to setup an email alert notification for failed SFTP jobs?
My DBA says their sftp script is a shell script not in Perl. If the return code won't work in the sftp shell script and I don't want to ask DBA to rewrite the script in Perl, what else should I try?
Thanks,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:13 AM
тАО04-28-2009 09:13 AM
Re: How to setup an email alert notification for failed SFTP jobs?
"the "script" will have to be written such that it scans to output log or takes some other action to confirm the file transfered completely / successfully. based on that action, the script should then return a zero or non-zero exit code....."
In other words: somebody's going to have to write / rewrite something to make this work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:14 AM
тАО04-28-2009 09:14 AM
Re: How to setup an email alert notification for failed SFTP jobs?
OldSchool wrote: "sftp, like ftp, appears to always return a zero, PROVIDED there isn't an error in sftp itself.
" So if there is an error, then it will return non-zero. And it should work for my sftp shell script to send failure alert notification.
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:18 AM
тАО04-28-2009 09:18 AM
Re: How to setup an email alert notification for failed SFTP jobs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:22 AM
тАО04-28-2009 09:22 AM
Re: How to setup an email alert notification for failed SFTP jobs?
No..No.NO!
sftp ALWAYS returns a zero, even if the commands fed to it fail. the only time you would get a non-zero is if something caused "sftp" itself to fail, like no space in process table.
Read and understand JRF's example. The transfer *FAILED* because of missing file, but the return code was 0 (indicating success)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:24 AM
тАО04-28-2009 09:24 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Here's a quick example of how you _might_ parse the SFTP session to determine success or failure:
# cat ./mysftp
#!/usr/bin/sh
typeset RC
typeset SFTPLOG=/tmp/sftplog.$$
trap 'rm ${SFTPLOG}' EXIT
exec 2> ${SFTPLOG}
sftp smhadt1 << EOF!
get /no/file /tmp/nofile
quit
EOF!
grep -iq "couldn't stat" ${SFTPLOG} && RC=1 || RC=0
echo "rc=${RC}"
exit ${RC}
...customize to your needs...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:28 AM
тАО04-28-2009 09:28 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Thanks. Is this example a Perl script? Will it work with my DBA's shell script? e.g. I copy/paste the example commands to my DBA's script on a HPUX 11.23 Oracle 8i server?
Regards,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:33 AM
тАО04-28-2009 09:33 AM
Re: How to setup an email alert notification for failed SFTP jobs?
> Is this example a Perl script?
No, it is a SHELL script. The '#!/usr/bin/sh' (first) line signals what interpreter to use --- the HP-UX Posix shell in this case.
> Will it work with my DBA's shell script?
You can certainly integregate and embellish the concept I presented. I would make the hostname, the source and the target file names arguments to pass, too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 09:34 AM
тАО04-28-2009 09:34 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 10:32 AM
тАО04-28-2009 10:32 AM
Re: How to setup an email alert notification for failed SFTP jobs?
I got an idea. How about comparing the check sum of the data files before and after the sftp transfer? If they are the same, then the sftp upload is OK, if the check sum is different, then it is failed. What do you think?
Thanks.
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 10:36 AM
тАО04-28-2009 10:36 AM
Re: How to setup an email alert notification for failed SFTP jobs?
> I got an idea. How about comparing the check sum of the data files before and after the sftp transfer? If they are the same, then the sftp upload is OK, if the check sum is different, then it is failed. What do you think?
That's OK _as_long_as_ your not moving a text file from UNIX to WINDOWS or vice versa using the ASCII mode of transfer. When you do that, a carriage return character will helpfully be added or subtracted from each "line" rendering the checksums different.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 10:58 AM
тАО04-28-2009 10:58 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Thanks for the reply. The sftp server is a UX server (not sure Sun or HPUX) and I will make sure we use binary mode to upload. Thanks again.
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2009 06:09 AM
тАО04-29-2009 06:09 AM
Re: How to setup an email alert notification for failed SFTP jobs?
while correct for ascii mode transfers in conventional FTP, some of the SFTP stuff, especially early open-source, don't make to dos2ux / ux2dos conversions. I won't go into how I happen to know about this ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2009 06:47 AM
тАО05-04-2009 06:47 AM
Re: How to setup an email alert notification for failed SFTP jobs?
Jan