Reputation: 9404
i am using sos job scheduler which support many language.i accept the shell script to write jobs but i am not a shell script writer.i want to implement a following points in job scheduler:
please help me to sortout the above discuss problem.
Thanks
Upvotes: 1
Views: 2410
Reputation: 342749
#!/bin/bash
hour=$(date +%H)
recipient="root"
case "$hour" in
[6-9]|1[0-5])
subject="success"
body="message"
;;
*)
subject="failure"
body="message"
;;
esac
echo $body | mailx -s "$subject" "$recipient"
Upvotes: 0
Reputation: 11268
There are two command line utilities that are helpful in this case:
date
: Displays the current time/date in a specified format.mail
: Sends e-mail from the command line.Since we only need the full hour for our logic I use the date format "+%H" (hour from 0-23). This gives the following script basis:
#!/bin/sh
hour=$(date +%H)
if [ $hour -gt 6 -a $hour -lt 15 ]; then
echo "message body" | mail -s Success <your e-mail address>
else
echo "message body" | mail -s Failure <your e-mail address>
fi
Upvotes: 1