Dynamic script and cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dynamic script and cron
# 1  
Old 06-21-2013
Dynamic script and cron

Hello friends,

I have a script.sh running, i need to move his generated file to another path and restart it every 24h.

is there a way to restart it from a script in a dynamic way without create a duplicate process?

Code:
script.sh &
mv file to /path
script.sh &

many thanks for your help
# 2  
Old 06-23-2013
Not clear..!! Can you please elaborate?
# 3  
Old 06-24-2013
HI,

I'd like to know how to restart a running script without generate a duplicate process!

example:

script1 is running

then i have to move his result file to another path

and then restart it

i need to do this task from a script scheduled by cron 1xday

thanks!
# 4  
Old 06-25-2013
Lets just say your script1.sh is creating result1.txt file.

Meanwhile, you are moving that file to another path (it might not be allowed). Then without killing the script or generating a new one, you have to make a change in your script1.sh so that it would start from step1 if the file is not found.

It will be easier for me to explain if you show me your script!
# 5  
Old 06-25-2013
# 6  
Old 06-25-2013
this one only needs to start one time and will self-restart ...
Code:
#! /bin/ksh

endtime=$(date +%H":"%M)  ## assumes endtime is exactly 24 hours after starttime

processfile(){
     curtime=$(date +%H":"%M)
     if [ "$curtime" != "$endtime" ]
     then
           some_command &
           mpid=$(ps -ef | grep "some_command" | awk '{print $2}')
           sleep 3600
      else
           kill -9 $mpid > /dev/null
           mv /dir/file /dir1/file.$(date +%Y%m%d)
           sleep 60 # <-- adjust to make sure starttime is not equal to endtime
           processfile
      fi
}

processfile

exit 0


Last edited by Just Ice; 06-25-2013 at 02:00 PM.. Reason: changed {} to () in /dir/file.${date +%Y%n%d}
This User Gave Thanks to Just Ice For This Post:
# 7  
Old 07-01-2013
Hi Just Ice,
thanks for your help,

i see that i have to modify dir paths, but i don't understand how to use your script for my needs,

please can you try to explain a bit more?

Thanks for your help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

2. HP-UX

Script dynamic find

Hi everyone, im try to write a small script to do something like this new_find.sh#!/usr/bin/ksh PAR=$1 PATH1=$2 find $PATH1 -name $PAR i need to pass the mask of the find by parameter but this dont work sh new_find *.sql /home/somthing any tip ? thanks! (3 Replies)
Discussion started by: lucasmanson
3 Replies

3. Shell Programming and Scripting

Help Create dynamic ksh script from a script

I am currently running 2 scripts to gather data for a 3rd script and would like to combine the 2 scripts into one. Having issues with the final output format. Note cannot post URL so replaced the http stuff with (name) in the examples All scripts contain #!/bin/ksh OS = Red Hat Enterprise... (0 Replies)
Discussion started by: pcpinkerton
0 Replies

4. Linux

issue on dynamic config script

I have one issue with my existing code.Actually i want to write parameter's at the end of the section not begin of section.please find my code snapshots... while read cfgfilename sectionname parameter do case "$cfgfilename" in cfgfilename) FILE=$HOME/config/$parameter unset... (1 Reply)
Discussion started by: suryanarayan
1 Replies

5. Shell Programming and Scripting

Help with dynamic script

Hey there, first post, somewhat-long-time lurker- This is on a Red Hat box Im working on a new site, and I have an idea for a dynamic CGI script to change who is "on call" Pretty much, it would pull next name from a text file each week to display it on the site, and just keeps cycling through... (3 Replies)
Discussion started by: rapenchukd
3 Replies

6. Shell Programming and Scripting

dynamic input to a script

Hi All, I am stuck in a situation where there is a script, say test1.tcsh which is being called from another script ,say test2.tcsh test1.tcsh:- #!/usr/local/bin/tcsh echo -n "Do you wanna test ??" set answ = $< echo $answ if ($answ =~ "y") then echo -n "enter your name <" ... (1 Reply)
Discussion started by: kavyak
1 Replies

7. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

8. Shell Programming and Scripting

dynamic editing using shell script

Hi, I would like to edit an input data-file by changing a variable in it in steps: For ex: If my input file is 'big.in', then it has the following data: 2.54 0.01 0.5 0.0 My source code then reads this above line, executes and gives out some output. Then , I want to increment... (1 Reply)
Discussion started by: habzone2007
1 Replies

9. Shell Programming and Scripting

creating dynamic shell script

Hello I am trying to create a dynamic ksh script and I have an issue. I have a script a.ksh and it has got the following lines (for example) #!/bin/ksh # trace mode +x : without trace -x : with trace set +xv echo hi, i am going to create a dynamic script now cat >> dynamic.ks <<EOF... (2 Replies)
Discussion started by: sundarkumars
2 Replies

10. Shell Programming and Scripting

dynamic global script

Hi, I have to create a global dynamic script which should ask for the env or some other variables and then create the soft links. let's say that I have to create ten soft links and the path for these soft links is different for each env for e.g: WDEV: /d02/app/applmgr/wdev/appl/CDCRM/bin... (2 Replies)
Discussion started by: isingh786
2 Replies
Login or Register to Ask a Question