Solved

script that terminates after a period

Posted on 2004-08-16
7
145 Views
Last Modified: 2010-04-22
Hi

I've got a program called scc and I've put this into a script to run daily, how can I write my script that scc will only run until november 2004 and musts never run after that

so in other words I've got my script (script.sh)
***************
inside script.sh:
./scc
***************
and cron runs it daily, I don't want to take out this script after after 3 months (november) I just want to write a script that checks the month and if it matches the 11th month it must not execute scc ?

Any help will be appreciated

Thanks

0
Comment
Question by:bunny47
7 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11812170
if [ `date +"%Y%m"` -ge  200411 ] ; then  exit; fi

However, I think it is a bad idea to litter the crontab with such "living-dead" entries.

0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 11815902
I agree with previous poster. It would be better for your script to do the check on date, and if it sees that november came just sed itself out of the crontab file :-)

if [ `date...` -ge 200411 ]; then
mv "crontab" orig
sed 's/.*"script-name".*//' < orig > "crontab"
killall -1 "crond"
fi
0
 

Author Comment

by:bunny47
ID: 11849747
Thanks for the help, so please help me out, I've got a program scc and it must never run after 3 months down the line and a message must pop up that says "scc does not run anymore"

if [ `date +"%Y%m"` -ge  200411 ] ; then  exit; fi

How can I put this in? Also if it becomes december will it also still not work 200412?

Thanks a mil
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11852474
> How can I put this in?

Just insert these lines into the script.sh before the call to scc
if [ `date +"%Y%m"` -ge  200411 ] ; then  
  logger -s -t $0 "scc should not run anymore.  Please remove the entry from crontab."
  exit;
fi


> Also if it becomes december will it also still not work 200412?

The -ge in the test means 'greater than or equal'  so the script
will still exit in december, and 2005, and forever after (well at
least until the year 21474836)

0
 

Author Comment

by:bunny47
ID: 11858706
Thanks alot, just this one last question to clarify

my scc program (script) looks like this:

mkdir /mnt/scc
mount -t vfat /dev/hda1 /mnt/scc
scc -a -f -j scc.out /

Now if I understand correctly it  must look like this:

if [ `date +"%Y%m"` -ge  200411 ] ; then  
  logger -s -t $0
  exit;
fi
mkdir /mnt/scc
mount -t vfat /dev/hda1 /mnt/scc
scc -a -f -j scc.out /
init 6

Is the above correct will my script and scc not run after the period spesified?

Thanks
0
 
LVL 1

Expert Comment

by:DJSara
ID: 11913920
Yes. The above is correct. Now, your script will  not run after the period specified.
Again, it is recommended that you remove the entry from crontab after it's use is over.
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 500 total points
ID: 11914179
My only comment is that
  logger -s -t $0
creates a log entry with no message (only timestamp and program name).

Note that my previous posting logs a message with the text you requested:
  logger -s -t $0 "scc should not run anymore.  Please remove the entry from crontab."

The latter is preferable for anyone perusing the system logs.  The nature of the
problem is mentioned as well a solution.

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Shell script awk command 2 105
Linux 10 108
Cloning a part of HDD MIPS Linux 16 112
Problem to run file 9 116
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question