The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-06-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Quote:
Originally Posted by Raynon View Post
Running the script continously means to say that i have to leave a command prompt window always open. Once closed, the process will be ended
Not at all, just move it to the background, no different to all the other daemonised stuff you are running on your system. If it likes to write to STDOUT, redirect this to a log file (or /dev/null if you prefer).
Quote:
Originally Posted by Raynon View Post
and also another disadvantage is that a infinite looping script will eat up alot of resources, wouldn;t it ?
Much as before, no problems here either. Just use sleep at the bottom of the loop to stop it thrashing.
Quote:
Originally Posted by Raynon View Post
So i still think cron is the more practical one.
Your call of course.
Quote:
Originally Posted by Raynon View Post
But i have no idea about anacron or control-m. Can you enlightened me on that ?
Anacron is a slighty more advanced version of cron, may or may not do what you want. Free (I think)
Control-M is a BMC product that manages scheduling at an enterprise level, it supports job dependancies, understands limited resources and works across multiple platforms. Costs a bit.

Google for more info on these
Quote:
Originally Posted by Raynon View Post
Can you give an example of script being re-entrant ?
Reentrant just means that it can be run multiple times at once without going wonky. One example:
Not rentrant:
Code:
#!/bin/sh
/usr/bin/do_some_stuff > /var/log/did_some_stuff.log
do some other things
if grep 'it worked' /var/log/did_some_stuff.log
then
  /usr/sbin/assume_we_are_good_to_go
else
  echo "Argh"
fi
Reentrant:
Code:
#!/bin/sh
/usr/bin/do_some_stuff > /var/log/did_some_stuff.$$.log
do some other things
if grep 'it worked' /var/log/did_some_stuff.$$.log
then
  /usr/sbin/assume_we_are_good_to_go
else
  echo "Argh"
fi
rm /var/log/did_some_stuff.$$.log
The first example could end up reading back the log of a different instance of itself. The second version includes the current process ID in the log file which prevents this happening.

Another, simpler, way is to just look in the process table for another copy of the script, if found exit immediatly.

Quote:
Originally Posted by Raynon View Post
I was thinking if i could make the script check for the process to see if the previous process have been completed, can any experts give me some examples of this ? I am using csh by the way.
(Assuming system V as opposed to bsd)
Code:
#!/bin/csh
set numprocs=`ps -ef | grep -v grep | grep $scriptname | wc -l | awk '{ print $1 }'`
if ($numprocs == 1) then
    # carry on
else
   echo "Another instance is already running, exiting..."
   exit 0
endif