Sponsored Content
Full Discussion: Bi-Weekly script
Top Forums Shell Programming and Scripting Bi-Weekly script Post 302651601 by agama on Tuesday 5th of June 2012 11:17:37 PM
Old 06-06-2012
The options you are trying to use with date aren't supported by all implementations. You can either install AT&T's AST tools which has a date command that does, or install the GNU date which also supports it. I personally would write it this way -- integer math is easier than trying to strip apart a human readable date and adjusting for month/year boundaries.

Code:
#!/usr/bin/env ksh                 
# should also work in bash if you prefer

now=$( date +%s )                                   # current time -- seconds past epoch
nrd=$(( (now - (now % 86400)) + (86400 * 14) ))     # two weeks from today (midnight) -- next run date
cache_file=$HOME/${0%%*/}.next                      # holds date that next run is allowed on
if [[ -f $cache_file ]]
then
    read ok2run <$cache_file
    if (( ok2run > now ))                           # next run date still in future
    then
        echo "abort: hasn't been too weeks; last execution was: $(tail -1 $cache_file)"
        exit 1
    fi
fi
printf "%s\n%s\n" $nrd "$(date)" >$cache_file       # save timestamp of next date ok and date for humans

# continue with rest of script
echo "good to go"       # just for testing/confirmation



It first gets the current time in seconds since the epoch (I believe most date commands support the +%s format, and someone will chime in here if I'm wrong). From there it computes the value of midnight two weeks out -- allowing the script to be run on the same day of the week (two weeks out), any time after midnight.

It uses a cache file to save the next valid execution timestamp, and a human readable string of the last time the command was executed. If there is no file it assumes that it is ok to run.

Hope this was at least some help.
This User Gave Thanks to agama For This Post:
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weekly statistics using while loop.

Hi people i have a situation here: my server generates a statistics text file every 30 mins. i have a script (txt2csv.sh) to convert all the statistics for the day into one csv file. Therefore i am doing a script to auto converts the text files into csv base on a weekly basis. the script is... (4 Replies)
Discussion started by: filthymonk
4 Replies

2. UNIX for Advanced & Expert Users

Scheduling bi-weekly through cron

Is there a way in AIX to schedule a script to run bi-weekly through cron? I have a script that needs to run every other Wednesday, and this is what I thought I had to enter in the crontab file: 00 08 * * 3/2 /home/user/user.script It didn't like that. It reports a syntax error. I'm almost... (5 Replies)
Discussion started by: LPT
5 Replies

3. Shell Programming and Scripting

Problem in Weekly file Transfer script

I have made a script which transfers some files of the entire week , but the script fails when the next month is started. For e.g; if i run the script on 5th may , but i need to transfer files of its previous week which is from 24th April to 30th april ,the script fails, i have this loop in the... (2 Replies)
Discussion started by: vee_789
2 Replies

4. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. Shell Programming and Scripting

Crontab running bi-weekly

Hi experts, Need your help to schedule the script(test.sh) bi-weekly in linux machine. script need to run at every alernate thursday at 9 am . Please help to run the same. (6 Replies)
Discussion started by: abhigrkist
6 Replies

6. Shell Programming and Scripting

Schedule and Run By weekly shell script in cronjob

Hi All, How to schedule a shell script(script name- byweeklyreport.sh) it should run by weekly in corn job or is there any script have to write to check week and then run the above script. example-1st run March 06 2013 2nd run March 20 2013 3rd run April 3 2013... (13 Replies)
Discussion started by: krupasindhu18
13 Replies
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 03:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy