Operating System - HP-UX
1752577 Members
4513 Online
108788 Solutions
New Discussion юеВ

standard redirect on SSH connect to ERR or root mail

 
SOLVED
Go to solution
Ratzie
Super Advisor

standard redirect on SSH connect to ERR or root mail

I am trying to figure out standard error and redirect on a crontab script that ssh /scp to another server. What I hope to do is trigger an err if key exchange in so successful.


I have:
00 6 * * * backup.ksh >> backup.log 2>&1
So bascially everything gets recorded to backup.log. But, if the ssh fails will I get notified?
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: standard redirect on SSH connect to ERR or root mail

Shalom,


But, if the ssh fails will I get notified?

No.

Put the notification code to send an email in backup.ksh

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ratzie
Super Advisor

Re: standard redirect on SSH connect to ERR or root mail

can you give me a hint on how to test this in ksh...
Dennis Handly
Acclaimed Contributor
Solution

Re: standard redirect on SSH connect to ERR or root mail

>how to test this in ksh?

If there is a specific exit status, you can check for that.
Or you can redirect stderr in your script, use grep to scan it and then send mail from the script.
If you still want those errors to be sent to backup.log you can do:
ssh ... 2> back.err
if [ $? -eq ?? ]; then
# specific error here? send mail
fi
# scan stderr
grep -q -e "message?" back.err
if [ $? -eq 0 ]; then
# found specific errors, send mail
fi

# copy ssh stderr to script stderr
cat back.err 1>&2
Ratzie
Super Advisor

Re: standard redirect on SSH connect to ERR or root mail

Much appreciated
Dennis Handly
Acclaimed Contributor

Re: standard redirect on SSH connect to ERR or root mail

># copy ssh stderr to script stderr
>cat back.err 1>&2

And of course clean up the temp file: rm -f back.err