Saturday, November 22, 2014

Linux: Run a program every hour

Saw this here (http://linux.die.net/Linux-CLI/scheduling.html):

You can also use the -f option to have at execute a particular file (a shell script).


at -f shell_script now + 1 hour

This would run the shell script 1 hour from now.



So I tested it as follows.  First, here is SAS program test_hourly.sas:

filename outbox email 'bqualls@firstanalytics.com';

data _null_;

file outbox
    to=('bqualls@firstanalytics.com')
    subject="Test hourly process"
    ;

put "This is a test run at &SYSDATE9 at &SYSTIME..";
put "This program will run again one hour from now.";
put " ";
put " ";
put " ";
put "(signed)";
put "The First Analytics Team";
run;



And here is the script:

#!/bin/bash
#schedule this same script to run again one hour from now
echo "sh test_hourly.sh" | at now + 1hr
#run sas program
sh runsas.sh test_hourly



And I started the script for this first time like this:

echo "sh test_hourly.sh" | at 5:30pm November 22



Note: must cd to the directory where test_hourly.sh exists before issuing the above instruction.



No comments:

Post a Comment