Solved

script that terminates after a period

Posted on 2004-08-16
7
143 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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 will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now