Run a job between times else run later

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run a job between times else run later
# 1  
Old 02-28-2015
Run a job between times else run later

Hi guys,

I have written a script that waits for a trigger file.
Then checks the time of the trigger.
if the trigger finished between 8pm and midnight then runs a job.
else it waits till 1am then runs a different job.
I am still very new to scripting so any suggestions to improve my approach would be greatly appreciated. I tend to over complicate my approach and want to learn more.

while : ; do
    [[ -f "/tmp/TRIGGER" ]] && break
    sleep 1
checktime=`ls -lart /tmp | grep TRIGGER | awk '{ print $8 }' | sed 's/://'`
echo "$checktime"

if [ "$checktime" -lt  "$mid ] && [ "$checktime" -gt "$start" ]
while [ $(date +%H:%M) != "01:01" ]; do sleep 1; done 1

# 2  
Old 02-28-2015
What system do you use? Does it have the stat command (or similar) providing file statistical info?
Why do you break the while loop instead of using the -f test's result?
Do you REALLY need to test every single second? Wouldn't 10, 30 or even 300 suffice?
When does this script run? Anytime during the day? Why don't you calculate the delay to 01:01 and do one big sleep instead of looping?

I think there's several examples of similar problems in these fora. Did you consider searching in here?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 02-28-2015
Hi, thanks for the reply. The system I use is a sun Solaris. The break part was just away of sitting there and waiting for a job to finish, this starts the same time the other job does (8pm) once the other job finishes It creates the trigger file. I get this to wait for it and kick off. I'm doing this the automate several tasks. Someone tried to do it via the cron and it went horribly wrong. You're right about the test, could increase it for sure. I can't put a big delay on it because the job I wait for can take a short time or a long time. So I get it to wait.
As for searching, I love to look around to learn, as I said I'm very new at this scripting lark Smilie I posted here to see others approach. I will continue to look and learn what i can as my approach can be very converluted. Any input positive or negative is help because I can hopefully learn from it.
# 4  
Old 03-01-2015
Some optimizations
checktime=`ls -l /tmp/TRIGGER | awk '{ print $8 }' | sed 's/://'`

or if you check very often
checktime=`date +%H%M`

Schedule the command for 01:00
echo " 1" | at 01:00

An exercise with the at command:
man at
at -l
at -r ...

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 03-01-2015
Thanks for the comments. Will look for the "at" command for sure, not seen that one before.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Set script to run during specific times

Hi all, I have this script which sends mail whenever the system is down. It works fine. Normally the system is down from 21 00 to 21 30 from Monday to Saturday and from 21 00 on Sunday to Monday 06 00 for maintenance. So I want the below script to run only when the system is up, i.e outside the... (2 Replies)
Discussion started by: frum
2 Replies

2. Shell Programming and Scripting

To run a job for every one hour and ...

Hi, Someone please help me to run the script to maintain a Job: Which can be run for every one hour and should maintain the last two hours files only. It should delete the rest of the files in a dir. Please suggest me with the sample script. Thanks !! Reagrds, Rama (5 Replies)
Discussion started by: ramagore85
5 Replies

3. Programming

Compare times to run a program - Serial vs MPI

Hi, I have a fortran program with serial and MPI version. I want to compare the time taken by these programs to run. I use ifort/gfortran compiler. How to compare the time taken by each program to run? Is there any sample code for comparison? Thanks, rpd (1 Reply)
Discussion started by: rpd25
1 Replies

4. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

5. Shell Programming and Scripting

Counting script how many times it run?

i should use this script runs how many times before ? how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies

6. Shell Programming and Scripting

Shell script to run x times

Hi, First i need to cd to this directory $SWDIR/util Second i need to run the following either 4 times or 20 times ./swadm add_process 1 BG Y how can i put this in a script which should ask for user input on how many times you want to run this Thanks, (5 Replies)
Discussion started by: lookinginfo
5 Replies

7. Shell Programming and Scripting

[bash] Run a program many times

Hi I'm running a program many times with differents input. I mean that i run my_prog with some parameters and i wait till the end, then i start again another simulations with some others differents parameters. Is possible to make it automatic with a script bash. Maybe i need some... (2 Replies)
Discussion started by: Dedalus
2 Replies

8. Shell Programming and Scripting

Need to run same script multiple times in parallel

Hi all, I have a requirement in which a script invokes a Java program. Lets say script ABC invokes a java program with cfg file a parameter. This script takes 10 minutes to execute . Like this ineed to run the program 10 times meaning 100 minutes if i do it sequentially. If i open... (2 Replies)
Discussion started by: rahman_riyaz
2 Replies

9. Programming

how to know the application run on which core, and run how many times on this core

I have a dual core pc, I write a application with two child process. I know I can add sched_get_cpu to know the process run on which core, but, it just when the sched_get_cpu is called, it will tell me the result, my quesion is how to know the child proceess spend how many times on one core. (2 Replies)
Discussion started by: yanglei_fage
2 Replies

10. Shell Programming and Scripting

Does not run via cron job

I have a perl script, when I ran manually it works perfect. I check the permissions which are fine. How can I find out why it is not running? how can I setup a log to check. I am running it on solaris 9. It compares multiple files, SCP and then send out an e-mail. As I said when I ran it... (2 Replies)
Discussion started by: amir07
2 Replies
Login or Register to Ask a Question

Featured Tech Videos