The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 09-29-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
A simple, though not particularly elegant, solution, is to write a wrapper script that executes your target script on the specified days, and call the wrapper script from cron.

eg (of the top of my head, not tested):
Code:
#!/bin/bash
FLAGFILE=/var/tmp/FlagFileNameThatIsUnique
DAY=`date +\%a`
case $DAY in
Mon) /path/to/script/to/be/run;;
Thu) [ -f $FLAGFILE ] && rm $FLAGFILE || (/path/to/script/to/be/run; touch $FLAGFILE);;
esac
set the cron entry to call the wrapper every monday and thursday.
The wrapper will only run the script on a thursday if the flagfile doesn't exist (and create the flagfile, once it has run). The next time it gets called on a thursday the flagfile will exist, so it doesn't run the script, just deletes the flagfile.

You may want to be careful where you store the flagfile, as on your system /tmp and /var/tmp may be 'cleaned' if the system is rebooted. You also have to ensure that the flagfile is uniquely named, so that nothing else can interfere with it.