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?

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

many thanks for your help

Not clear..!! Can you please elaborate?

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!

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!

Hi, here you will find the script:

Code Snippets - twitstreamer - a simple commandline tool for reading tweets from the twitter streaming API

thanks for your help.

this one only needs to start one time and will self-restart ...

#! /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

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!

see comments in code sample ...

#! /bin/ksh

PATH=/usr/bin:/bin:/usr/sbin:/sbin

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

processfile(){
     curtime=$(date +%H":"%M)
     if [ "$curtime" != "$endtime" ]     ## checks that current time is not same as endtime
     then
           some_command &      ## put your actual command block here
           mpid=$(ps -ef | grep "some_command" | awk '{print $2}')
           sleep 3600                ## wait an hour
      else
           kill -9 $mpid > /dev/null     ## kill background process id
           mv /dir/file /dir1/file.$(date +%Y%m%d)
           sleep 60 # <-- adjust to make sure starttime is not equal to endtime
           processfile    ## call back function to restart processing over again
      fi
}

processfile ## start function to generate and move file

exit 0