Cron running shell scripts.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron running shell scripts.
# 1  
Old 09-26-2001
Question Cron running shell scripts.

What are the rules of calling shell scripts in cron.

How do I go about setting up the correct PATHS that calls a script, which then calls another sub script all of which has to retain the orginal PATHS and VARS that I've set up in first script

Confused..

ok
Well Cron calls a script called script.cron - This script contains environment setups etc, and then calls another script script2.ksh

I want the script2.ksh to retain all the environments etc that was set in script.cron
# 2  
Old 09-26-2001
What you have should work. I have the same setup.
I kick off a script, say, first.sh which contains all the necessary paths, variables, etc and this first.sh script kicks off the next one which kicks off the next one, etc.

crontab:

00 22 * * 1-5 ksh $HOME/bin/first.sh > $HOME/log/first.log 2>&1

This has been working for as long as I can remember and I think you are on the right track.

first.sh scripts:

PATH=$PATH:/usr/bin:/usr/local/bin:$SQLDIR/bin:$HOME/bin
USERID=user01
PW=mypasswd
LOGFILE=$HOME/log/logfile.log
LIBPATH=...whatever
etc

. $HOME/bin/second.sh

you get the idea.
# 3  
Old 09-26-2001
You need to use the "export" command in the first script to put a variable in the environment. The second script will inherit the environment from its parent.

The other thing worth mentioning is that a cron script must be self-sufficient. Don't depend on setup stuff from .profile. So set variables like PATH in the script. Don't rely on the the PATH you inherit from cron.
# 4  
Old 09-26-2001
I suppose you can use 'export' but my first.sh script doesn't have it and my 100 or so scripts that come after runs fine.

Also, isn't there a limit to how many processes you can chain together? After a certain amount of this type of call:

. $HOME/bin/twenty.sh

I have to do this:

ksh $HOME/bin/twentyone.sh

for recursive issues?? otherwise I get an error...Do you know why? Not sure of the exact count but to be safe I remember to use explicit calls intermittently after so many implicit calls. Don't go overboard with 'ksh' too though.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Running multiple php scripts into one php only, cron mail alert problem...

hi, while separated they produce the usual mail alert and i can see the output... if i write into the php script: <?php system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script1.php'); system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script2.php'); system('php -f... (0 Replies)
Discussion started by: 7stars
0 Replies

2. Solaris

running scripts from cron

I need to run a script (from cron) that runs a second script. What worries me is that second script, when run from bash, upon finishing doesn't return to bash unless I press the 'Enter' key. I presume that's because last command in that script ends with & Could that be a problem for cron?... (2 Replies)
Discussion started by: orange47
2 Replies

3. Shell Programming and Scripting

Running shell scripts from command

I have written a few shellscripts to run a videogame (starcraft) at different patched versions. For example bw113 runs the 1.13 version of the game. These works perfectly when I run them from command line (./bw113). However I cannot get it to work via mouseclick. Some Information: - I have... (5 Replies)
Discussion started by: lordsloth
5 Replies

4. Shell Programming and Scripting

Automatic running of Shell scripts

Hi, I have this problem of merging 2 shell scripts and run it one after the other. For eg: script A runs to give OutputA. This OutputA should become the input of script B which will run to give OuputB. Now this has to happen automatically i.e, script A and script B should run consecutively one... (1 Reply)
Discussion started by: Vindhyaauri
1 Replies

5. Shell Programming and Scripting

Running 2 scripts one after the other using cron

I would like to run two scripts using cron one immediately after the other. Is it enough to put them one after another in the cron file to run at the same time, or will this cause them to run concurrently? (4 Replies)
Discussion started by: 3210
4 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

Running shell scripts from web browser

I am in need of a mechanism to run shell scripts from web browser. Could any one of you guide me as to which technology to choose? I have some scripts which take some arguments. Appreciate you response. (7 Replies)
Discussion started by: corleone
7 Replies

8. UNIX for Advanced & Expert Users

unix shell scripts for running on solaris

am new to programmming any body suggest , how to execute, shell script interactively and like stream line edit (3 Replies)
Discussion started by: srini_ibmadmin
3 Replies

9. UNIX for Dummies Questions & Answers

running vendor shell scripts

Does anyone run a lot of SH (shell script) commands from vendors. i.e... product installations. And do you edit/change as a rule of thumb? I done a lot of product installs and some tend to think we should edit/change a vendors SH script. I am just looking for your thoughts. Thanks. (1 Reply)
Discussion started by: Javagate
1 Replies

10. UNIX for Dummies Questions & Answers

Running shell scripts on a remote server

Hi - I am running Mac OS X (Terminal) at my current workstation, and I would like to telnet to my local server to run a shell script. The local server is a Solaris machine (don't know the version or the type of Unix being run on it, sorry.) The problem I have is that when I create a #!/bin/sh... (2 Replies)
Discussion started by: pepintheshort
2 Replies
Login or Register to Ask a Question