Scheduling cron job

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Scheduling cron job
# 1  
Old 06-19-2013
Scheduling cron job

Hi Everybody,

I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval.

Regards,
Mastan
# 2  
Old 06-19-2013
Possibly better to wrap your script as a loop, e.g.
Code:
#!/bin/ksh
lastsec=-1         # Set to an invalid second count to ensure an immediate start.
while true
do
   currsec=`date +%S`
   ((testsec=$currsec/5))
   ((testsec=$testsec*5))
   if [ $testsec -eq $currsec -a $testsec -ne $lastsec ]
   then
      run-your-code-here
   else
      sleep 1
   fi
   lastsec=$currsec
done

Of course, this never ends unless you put an exit in the code somewhere. You could consider testing for the minute to have passed and end, then schedule it with cron every minute, that way if it ever crashed out, it would be started again.

Not a great way, but it's an option. One wonders why you need to run it every five seconds. Can you enlighten us?


Anyway, I hope that this helps or gives you useful thoughts.


Robin
Liverpool/Blackburn
UK
# 3  
Old 06-19-2013
Or:
Code:
watch -nX your_script

Where X is any number of seconds.
# 4  
Old 06-19-2013
or you could just let the script sleep every 5 seconds ... start it from cron every start of the hour ... script sample below wil exit if $lockfile exists ... removing lockfile will kill running script ...
Code:
#! /bin/ksh
lockfile=/tmp/lockfile

repeatJob(){
    echo "boo"
    echo "duh\n"
    if [ ! -f $lockfile ]
    then
        break
    else
        sleep 5
        repeatJob
    fi
}

if [ ! -f $lockfile ]
then
    touch $lockfile
    repeatJob
else
    echo "$lockfile exists. Exiting."
    exit 1
fi

exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Job Scheduling

Hi All, I am new to unix and i have a task in front of me. The code part is "android update sdk" . I need to crontab this process. Hence i have written a script that runs the above command and sends a mail once the update is done. The problem with the automation is the installer asks for a... (5 Replies)
Discussion started by: Kashyap
5 Replies

2. Shell Programming and Scripting

scheduling a job using at command

Hi All, I've been trying to schedule a job using the at command on Solaris 5.10 but i've been running into some issue. ( Not allowed to use cron :wall: ) I have a script that reads a logs file, does some iteration and cat's the output in an email . ## the o/p of /home/myscript.sh is : ... (2 Replies)
Discussion started by: Irishboy24
2 Replies

3. Shell Programming and Scripting

Cron Job Scheduling

Hi All, I have a script which is scheduled in the Cron. It runs every 10th and 40th min of an hour.The job has to run every 30min. But, I do not want to have the 00:10 MST run every day.Is it possible to exclude that run from the schedule?Or any other way through which i can run my job every... (4 Replies)
Discussion started by: sparks
4 Replies

4. Shell Programming and Scripting

Scheduling Cron job-Problem

Hello All, I want to run a script for every 5 minutes interval.So i developed a script which has to be scheduled to run for every 5 minutes. That script internally runs another script. But the problem is it is not executing properly. Can anybody throw some light on this. Below are the code... (4 Replies)
Discussion started by: RSC1985
4 Replies

5. UNIX and Linux Applications

Job Scheduling (Autosys)

Hello! I will be working with Autosys and I am looking for individuals that have knowledge of this UNIX application. Thank-you! (3 Replies)
Discussion started by: preshe79
3 Replies

6. Shell Programming and Scripting

Job Scheduling

I am working on UNIX AIX system, with Oracle OS. We are not supposed to use any tools to schedule our unix shell scripts. Basically we have to make use of Oracle tables and Shell scripts to manage dependencies, restartability, scheduling, parallelizing,etc. If anyone has worked/ is working... (4 Replies)
Discussion started by: singhabhijit
4 Replies

7. UNIX and Linux Applications

Job Scheduling

I am working on UNIX AIX system, with Oracle OS. We are not supposed to use any tools to schedule our unix shell scripts. Basically we have to make use of Oracle tables and Shell scripts to manage dependencies, restartability, scheduling, parallelizing,etc. If anyone has worked/ is working... (1 Reply)
Discussion started by: singhabhijit
1 Replies

8. UNIX for Advanced & Expert Users

cron job scheduling

Hi, How can I configure cron file , to execute a script on evey alternate saturdays ? I am using AIX 5.0 machine Thanks in advance Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies

9. Shell Programming and Scripting

Job Scheduling

Hello, I want to know about job scheduling utilities available in unix. It should not be responsible just for starting the job like in case of cron but should also be able to handle the execution of jobs. Regards, Ritesh (1 Reply)
Discussion started by: turlapaty
1 Replies

10. UNIX for Dummies Questions & Answers

problem with scheduling a job

I scheduled 2 Oracle jobs to run on IBM AIX 4.3.3 at 06:50 and 06:58 on 02/02/03 with the below syntax: $ at 06:50 02/02/03 /orac/ora11/temp/sun_job1.sh Job oracle.1044175800.a will be run at Sun Feb 2 06:50:00 2003. $ at 06:58 02/02/03 /orac/ora11/temp/sun_job2.sh Job... (1 Reply)
Discussion started by: ted
1 Replies
Login or Register to Ask a Question