I have a shell script that checks a file state.txt, deletes fit.bin if state.txt is empty. I cron this at 2am, I will want the script to stop by 8am irrespective of the value of state.txt, any ideas?
I have a shell script that checks a file state.txt, deletes fit.bin if state.txt is empty. I cron this at 2am, I will want the script to stop by 8am irrespective of the value of state.txt, any ideas?
Maybe i oversee something, but i think you are doing it more complicated than necessary: put one script in cron at 2 am, put a second one which kills the first one (if it is running at all) in cron at 8 am. You can create a "PID file" at the start of the first script which you remove at program end:
This is your work script, which you will start at 2 am. It cannot be started twice (the second instance would terminate). Trap 0 is a "virtual trap" (for lack of a better word), which is not executed upon getting a certain signal but on exiting the shell process (^= terminating the script in any way).
The content of the PID file is only the PID of the running script instance.
Your termination script looks like this:
Note that both scripts are only rough sketches. You might want to add all sorts of checks, ifs and whens.
Thanks bakunin. For example, if script terminates successfully at 2:30am, and the PID is reassigned to another process before 8am, won't that cause a process to be terminated wrongfully when the second script is run at 8am??
Thanks bakunin. For example, if script terminates successfully at 2:30am, and the PID is reassigned to another process before 8am, won't that cause a process to be terminated wrongfully when the second script is run at 8am??
First: it is highly unlikely that the PID is recycled so fastly. PIDs are - for a reason - supposed to be almost random.
Second: even this small chance is further reduced to absolute zero because the terminating script will delete its PID file upon ending. "trap 0" is executed every time the script ends, regardless of how it ends. The action part of the cleanup script will only run when the PID file exists, not when the PID is in use. This means: when the script terminates at 2:30 it will remove the PID file, at 8:00 the cleanup script will start, fail to find a PID script (the "if [ - e file..." will evaluate to "false") and the cleanup script will do nothing (in fact it will issue the warning, see the else-part).
I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Hello All,
As I stated in subject, I need a command to terminate my tcpdump command in a certain time period. (using HP-UX)
I am using below one to terminate when number of captured packages reach 3 limit.
But what if there will no packet come in 5 min for instance?
Please help me to find a... (2 Replies)
Hi,
I am writing a shell script to run a process and write the output of the process to a file.
Inside program.sh:
./process.sh > tempfile
..
open tempfile
do the following
But the problem is that process.sh is running indefinitely and program.sh is not executed completely. Can... (4 Replies)
Dear experts,
I have an epoch time input file such as : -
1302451209564
1302483698948
1302485231072
1302490805383
1302519244700
1302492787481
1302505299145
1302506557022
1302532112140
1302501033105
1302511536485
1302512669550
I need the epoch time above to be converted into real... (4 Replies)
I'm working on a script to make backup of various folder located on various host using different OS.
I got a strange behaviour because the script donět process all lines of a configuration file, the script execute only one loop even the input file have 6 lines:
This is the script:
#!/bin/bash... (4 Replies)
Hi all ,
i am trying to calculate time difference btw the script execution
I am using solaris
start_time=`date +%s`
sleep 2
end_time=`date +%s`
duration=`expr $end_time - $start_time`
when i try to subtract i get the error
line 13: %s - -time : syntax error: operand expected... (3 Replies)
when I get time
some times it like
$hwclock -r
Mon 07 Jul 2008 20:01:48 PM GMT -0.486264 seconds
some times it like
$hwclock -r
Mon Jul 7 20:01:48 2008 -0.547393 seconds
the sequence is not the same all the time and I just want to use "hwclock" not "date" to get time
I... (8 Replies)
Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Hai all..
How do i terminate my telnet session automatically when my java applicatiion exits. i have a file run which executes my java application and takes care of all class and library path settings prior to the execution. I would like to terminate my session when my application exits. The... (4 Replies)