Set up CRON


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Set up CRON
# 1  
Old 02-28-2012
Set up CRON

Hello,

I would like to set-up a script in cron on a Solaris 10 sever which would run once in 3 weeks. I am not supposed to make any changes in the script itself.

Can anyone advise how it can be done?
For any queries, kindly let me know.


Thanks.
# 2  
Old 02-28-2012
I don't have access to a Solaris machine and have no idea how cron on Solaris works. Right now I'm working on RHEL GNU Bash.

Here's one way to do it. You need not make any changes to the original script. You can write a wrapper script and have a tmp file containing the date of first run (date in tmp file should be in yyyymmdd format). Place this wrapper script and tmp file in same directory.

Wrapper script: A condition checks if the difference between current date and the date in tmp file is 21. If yes, run original script and change date in file to current date.

Code:
$ cat /home/user/date.tmp
20120207

The below code is untested.
Code:
$ cat /home/user/wrapper_script.sh
#! /bin/bash

if [ $((`date +%Y%m%d` - `cat date.tmp`)) -eq 21 ]
then
    date +%Y%m%d > date.tmp
    sh original_script.sh # Run original script.
fi

Now for the cron entry (Invoke wrapper script every monday at 9am):
Code:
0 9 * * 1    sh /home/user/wrapper_script.sh

# 3  
Old 02-28-2012
thanks, but ...

Thanks for the above suggestion.
But .. since this is a restricted environment (client setup) I am not allowed to place my scripts on it, so I have to do it with cron.
If you would have done it on GNU, how would you do it with cron and not with script?
A few suggestions (to test out) would be appreciated!.
Thanks.
# 4  
Old 02-28-2012
One way without a wrapper script and temporary file could be checking if the number of weeks since 1970-01-01 is divisible by 3. The crontab entry for every 3rd monday at 9 am:
Code:
0 9 * * 1  [ $((`date +%s` / 60 / 60 / 24 / 7 % 3)) -eq 0 ] && /path/to/your/script

# 5  
Old 02-28-2012
Quote:
once in 3 weeks
From the sort of answers you are getting this is ambiguous.

Do you want to run this existing script once only on a specific date and time in three weeks time?
If that is true, I would use an "at" job (which uses cron). See "man at".

OR:

Do you want you run this existing script every third week at a specified time for evermore?
# 6  
Old 02-28-2012
Quote:
0 9 * * 1 [ $((`date +%s` / 60 / 60 / 24 / 7 % 3)) -eq 0 ] && /path/to/your/script
This crontab line will not work in Solaris because the default Shell for cron is the old Bourne Shell which does not support $(( )) syntax.
Also it contains a percentage sign "%" which is a special character in crontab files on all platforms.
# 7  
Old 02-28-2012
Quote:
Originally Posted by methyl
This crontab line will not work in Solaris because the default Shell for cron is the old Bourne Shell which does not support $(( )) syntax.
Also it contains a percentage sign "%" which is a special character in crontab files on all platforms.
Hmm, the calculation could be done using bc, but the problem with the percentage sign still remains, which makes an approach using the date command futile...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problems with set up Cron

Hi I want to set up a cron for every 15 minutes between some hours. Can you tell whether the below command will work. Getting confuse because my time goes from night to next day morning. i want to setup 8 PM to next day 10 AM. */15 20-10 * * * sh abc.sh (1 Reply)
Discussion started by: raju2016
1 Replies

2. Shell Programming and Scripting

Shell script to set trap for finding cron job failures

Unix box: solaris 5.8 Server: IP Need to to set trap for cron job failures by writing a shell script (5 Replies)
Discussion started by: ChandruBala73
5 Replies

3. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

4. Solaris

LC_ALL & LANG are set OK, but others couldn't set locale correctly.

Hi, I have a Solaris (SunOS 5.10) installed, by default with the en_AU.UTF-8 locale. I want to change it to en_US.UTF-8 With AU, I have no issues whatsoever, so I installed the language package and now locale -a shows "en_US.UTF-8". Problem is even with LC_ALL set in etc/default/init, the... (2 Replies)
Discussion started by: asdfg
2 Replies

5. UNIX for Dummies Questions & Answers

How to set server's ip address, router, network mask and set if it is an internal or external ip?

Hello, I need to write a program which sets server's ip address, router, network mask. Program also should set if it is an internal or external ip. Maybe someone can help me ? Any information from u is very useful :b: I stopped at .. :( #!/bin/sh A=`hostname -i` echo "server ip address is $A"... (4 Replies)
Discussion started by: zagaruika
4 Replies

6. UNIX for Dummies Questions & Answers

Re : Set multiple cron jobs in one crontab file

Hello All, Hopw all is fine. I am newbie to Unix. I am using Bourne Shell (sh). One of the question I have is that I am trying to read XML file and based on reading that XML file I want to run different java programs at different hours. Meaning 05 14 * * * java ./program1 10 14 * * * java... (3 Replies)
Discussion started by: samshaw
3 Replies

7. Shell Programming and Scripting

set EDITOR=vi -> default editor not setting for cron tab

Hi All, I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by set EDITOR=vi it does not open a vi editor , rather it do as below..... ///////////////////////////////////////////////////// $ set... (6 Replies)
Discussion started by: aarora_98
6 Replies

8. Shell Programming and Scripting

how to set classpath in cron

i have written shell script that script has path to java programwhen irun this script in terminal i get the output but when irun in cron it gives me eror.plz send me code to set classpath #! /bin/bash javac Copy.java /usr/bin/java Copy plz help me out how should i write classpath... (1 Reply)
Discussion started by: sari
1 Replies

9. UNIX for Dummies Questions & Answers

set up cron permission in Sun

Under this directory: /var/spool/cron/crontabs/ I have the following users: adm lp oracle root sys uucp I believe who are able to start a cron job. I am trying to create a cronjob under user banjob so that it can delete files older than 30 days. How can I add user banjob... (4 Replies)
Discussion started by: simt
4 Replies
Login or Register to Ask a Question