Running scripts within scripts from cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running scripts within scripts from cron
# 1  
Old 07-14-2009
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.
#!/bin/ksh

echo Test runs `date`

. ~/.bash_profile

cd /u01/home/bin

./java_env.ksh

./trigger_process.ksh checkstatus
The java_env.ksh sets up various variables like JAVA_HOME and LOG_FILE using an export <VARIABLE NAME> commands.

The trigger_process.ksh is a generic script which calls a java class which is passed into it.

When I run the checkstatus.sh script from the shell it works fine however when it runs from cron it doesn't. The variables exported in ./java_env.ksh are not available to the trigger_process.ksh script.

Is there a way to run the cron job so that the variables are available globally?
# 2  
Old 07-14-2009
source the java_env.ksh script...

if the checkstatus script works from your command line then the contents of the varaibles in java_env.ksh were already defined in your process before you even entered the name 'checkstatus.sh' on the command line. You have to source the java_env.ksh in order to make the env variables available.
# 3  
Old 07-14-2009
Thanks Jim but I'm not sure I understand you. The variables aren't available from my shell they are being created by the java_env.ksh script.

Not sure what you meant by

"You have to source the java_env.ksh in order to make the env variables available."

Thanks for your help.
# 4  
Old 07-14-2009
Quote:
Originally Posted by sirbrian
Thanks Jim but I'm not sure I understand you. The variables aren't available from my shell they are being created by the java_env.ksh script.

Not sure what you meant by

"You have to source the java_env.ksh in order to make the env variables available."

Thanks for your help.
Start the script with a dot and a space in front of the scriptname:

Code:
. ./java_env.ksh

Regards
# 5  
Old 07-14-2009
Cheers dude,

Thats exactly what I needed to do.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Cron scripts security

Hello everyone, I have an AIX 6.1 machine and i experienced a problem with my cron scripts. It appears that somebody renamed a cron script so crontab could not execute it. Is there a way to put some security on cron scripts so nobody else except root can rename or delete a cron script? Or they... (6 Replies)
Discussion started by: omonoiatis9
6 Replies

2. 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

3. 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

4. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

5. Shell Programming and Scripting

cron job is not working for two scripts

Hi Gurus, I have a test unix server in which currently some unix cronjob are running. I have written two script one is a shell script in which env variable are there (in that i am exporting those variables). I have also written a perl script . when i am running at the shell manually like... (5 Replies)
Discussion started by: sanjay.login
5 Replies

6. Shell Programming and Scripting

Linux - scripts not working in cron

hi all, i have scripts executable in manully, but not working in cron. any ideas? thanks a lot? * * * * * /home/dir/dir/file.sh #! /bin/sh alarmPath="/home/dir/monitoringAlarm" alarmDateTime="$(date +%Y%m%d) $(date +%H%M%S)" tomcatPID=`pidof /usr/local/jdk1.6.0_13/bin/java` echo "tomcat... (3 Replies)
Discussion started by: maxlee24
3 Replies

7. UNIX for Dummies Questions & Answers

Cron changing folder for scripts

I would like to ask if cron when running a planned script changes the current folder for the script. Thank you! (2 Replies)
Discussion started by: MartyIX
2 Replies

8. 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

9. Shell Programming and Scripting

help in cron scripts

Hi, i have scheduled my scripts in cron, some time the script doesn't runs ..which will impact me a lot, can some one help me such that mail has to come stating script has run successfully/unsuccessful any help will be appreciated.. thanks in advance, geeko (0 Replies)
Discussion started by: geeko
0 Replies

10. UNIX for Dummies Questions & Answers

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... (3 Replies)
Discussion started by: cfoxwell
3 Replies
Login or Register to Ask a Question