views:

57

answers:

2
+1  Q: 

sos Job scheduler

Hi all,

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:

  1. execute a shell script A. script A return "success" if time is between 6:00AM and 3PM.else it return "fail".
  2. on "success" execute a shell script C or on "Fail" it execute shell script B.
  3. Script B and Script C send email with“Success” or “Failure” in subject line.

please help me to sortout the above discuss problem.

Thanks

+1  A: 

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
schot
A: 
#!/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"
ghostdog74