Operating System - HP-UX
1753481 Members
4659 Online
108794 Solutions
New Discussion юеВ

Re: How to setup an email alert notification for failed SFTP jobs?

 
SOLVED
Go to solution
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi James,

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
OldSchool
Honored Contributor

Re: How to setup an email alert notification for failed SFTP jobs?

as noted previously:

"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.
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi James,

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
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Just got OldSchool's new update. Thanks.
OldSchool
Honored Contributor

Re: How to setup an email alert notification for failed SFTP jobs?

"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"

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)
James R. Ferguson
Acclaimed Contributor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi (again) Jan:

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...
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi James,

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
James R. Ferguson
Acclaimed Contributor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi (again) Jan:

> 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...
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Thanks, James. I will try this, please wait.

Jan
Jan Shu
Regular Advisor

Re: How to setup an email alert notification for failed SFTP jobs?

Hi James/OldSchool/SEP,

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