Sponsored Content
Full Discussion: Bi-Weekly script
Top Forums Shell Programming and Scripting Bi-Weekly script Post 302651595 by RM1006 on Tuesday 5th of June 2012 09:28:41 PM
Old 06-05-2012
Bi-Weekly script

Hi,

I found the following biweekly script by searching google:

###############################################
why not schedule it weekly, cache the "date" of the last run to a
file, and then at the beginning of your shell script
compare the current date with the cached date and only approach to the
real code when they are two-week difference.
This logic should be very easy to implement in both cronjob and the
shell script.

Code:
#/bin/sh
 
BASEDIR=/path/to/cron/bin
CACHEFILE=$BASEDIR/lastrun.txt
TODAY=$(date +%F)
DAY14=$(date -d'-14 days' +%F)
 
if ! [ -s "$CACHEFILE" ]; then
date +%F > "$CACHEFILE"
else
LASTRUN=$(<"$CACHEFILE")
if [ "$DAY14" != "$LASTRUN" ]; then
echo "not scheduled"
exit
fi
echo "$TODAY" > "$CACHEFILE"
fi
 echo "program here"

####################################################
This line gives error when i use -x debug option, can someone please help me to fix this?
Quote:
+ date '-d-14 days' +%F
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

Thanks
Sincerely,
RM
 

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
WEEKLY(5)						      BSD File Formats Manual							 WEEKLY(5)

NAME
weekly, weekly.conf -- weekly maintenance DESCRIPTION
The /etc/weekly script is run, by default, every Saturday morning on a NetBSD system. The /etc/weekly.conf file specifies which of the stan- dard weekly services are performed. The variables described below can be set to ``YES'' or ``NO'' in the /etc/weekly.conf file. The default settings are in the /etc/defaults/weekly.conf file. (Note that you should never edit /etc/defaults/weekly.conf directly, as it is often replaced during system upgrades.) rebuild_locatedb This rebuilds the locate(1) database, /var/db/locate.database, which must also exist, in order to be rebuilt. rebuild_mandb This rebuilds the apropos(1) database /var/db/man.db, using makemandb(8) with the -f option. rebuild_whatisdb This rebuilds the whatis(1) database(s). Note that NetBSD provides a default whatis.db for the system manual pages and this may not be needed. (Adjust your /etc/man.conf as necessary; see man.conf(5) for details.) FILES
/etc/weekly weekly maintenance script /etc/weekly.conf weekly maintenance configuration /etc/weekly.local local site additions to /etc/weekly SEE ALSO
daily.conf(5), monthly.conf(5) HISTORY
The /etc/weekly script first appeared in 4.3BSD. The /etc/weekly.conf configuration file appeared in NetBSD 1.3. BSD
March 6, 2012 BSD
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy