HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

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

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