Calling scripts from with scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling scripts from with scripts
# 1  
Old 07-23-2012
Question Calling scripts from with scripts

Hi all, I'm wondering if you could give me some advice. I am new to scripting and am getting rather frustrated that i can get my script to call another script if certain criteria is met, via command line, but I cannot get the same script to work thru the cron jobs.

My first script monitors diskspace, and if disk space hits x% free then it calls another script with runs an autoarchive program.
Code:
#!/bin/ksh
# Define the hostname of the server
SRVNM=`uname -n`
while read -r FS MAXCAP
do
CAPACITY=`df -h $FS | grep -v avail | awk {'print $5'} | awk -F% {'print $1'}`
echo $CAPACITY
echo $MAXCAP
echo $FS
if test $CAPACITY -gt $MAXCAP; then
./archive.sh&
EOF
fi
done < $ADMINDIR/SIDlog.dat
exit 0
EOF

the archive.sh script is
Code:
#!/bin/ksh
# The directory this script resides in
ADMINDIR=/usr/local/bin
nohup brarchive -c force -u uname/pwd -p /oracle/SID/102_64/dbs/init.sap -save_delete -d util_file -r /oracle/SID/102_64/dbs/init.utl -k no -l E
exit 0

can anyone help please???
thanks in advance
Alison

Moderator's Comments:
Mod Comment Code tags please

Last edited by jim mcnamara; 07-23-2012 at 04:37 PM..
# 2  
Old 07-23-2012
Code:
if test $CAPACITY -gt $MAXCAP; then
/full/path/to /archive.sh &

You should add
Code:
wait

as the last line of your script - it will wait for the child processes you are creating. Otherwise those processes will be terminated.
# 3  
Old 07-23-2012
What sets the ADMINDIR variable for the first script?
If this is setup in your .profile, .kshrc or /etc/profile it won't be setup when running script via cron.

You are best to set this value at the top of the script:

Code:
#!/bin/ksh
# Define the hostname of the server
SRVNM=`uname -n`
# The directory this script resides in
ADMINDIR=/usr/local/bin
while read -r FS MAXCAP
...

# 4  
Old 07-24-2012
@Jim, thanks for the info, having the full path to the script helped, also adding wait at the end of the script seems to allow the archive.sh script to run (I have a line at the end of both scripts that logs when the script was last run.
echo log space monitoring script, logmon.sh ran on `date` >>/usr/local/bin/archive.log

before adding the wait only the monitoring script registered. After adding the wait the archive script registers as having run, but the archive script, does not archive - any ideas? its driving me loopy!
thanks in advance
alison

---------- Post updated at 03:28 PM ---------- Previous update was at 03:27 PM ----------

@Chubler -apologies, I omitted to paste that line of the script into the details. In the full script it is there.
# 5  
Old 07-24-2012
Niot sure what you are asking - for example you have spurious "EOF" entries in there, not a shell keyword, not a command.

Anyway - what is the reason for the nohup [long command]? ...specifically nohup stops the process from being terminated if the terminal becomes disconnected. So, I do not see what nohup is doing. I am assuming the problem lies in the brarchive call.

I'm not a sap programmmer. So I do not know a priori what commands like brarchive do.
# 6  
Old 07-26-2012
Hi Jim
thanks for you feedback

In the first script I put the EOF in because if I don't I get this error

/logmon.sh[35]: EOF: not found

nohup is just my quick and dirty way of writing the output of the brarchive commend to a log file Smilie

if I run the logmon.sh file manually, and the criteria is met, then it calls the autoarch.sh which executes as it should. It backs up the SAP archive logs, so I don't think there is anything wrong with the brarchive call.

any suggestions please?
thanks
Alison

---------- Post updated at 05:15 PM ---------- Previous update was at 02:27 PM ----------

Oh I am soooo close! thanks for all you help so far, its definitely been pointing me in the right direction.

My only issue now is that the child script exits before the brarchive command has started, any ideas?

thanks in advance guys
alison
# 7  
Old 07-26-2012
What does your code look like now?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

2. Shell Programming and Scripting

Calling scripts from other script.

I need to call 3 different shell scripts from 2 different scripts, one is a perl script and other is Shell script. In Case -1 : The perl script is myperlscript.pl and the name of three shell scripts which need to be called from the perl script are a1.sh, a2.sh and a3.sh. Each shell script... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

3. Shell Programming and Scripting

Calling scripts within script

Hi, I have written a some six scripts to move large files and re-size them. This has been done step by step, taking backup, creating the new files, merging the files, removing the temporary files created. Since these files are around 500 MB, each step takes somewhere between 1 to 5 mins. ... (1 Reply)
Discussion started by: baanprog
1 Replies

4. Shell Programming and Scripting

Calling Multiple Scripts - stops after 1

I have created a script to call 2-3 shell scripts to be execute in succession, however, it seems that after the first shell script completes, the entire script exits out. Example: 1stJob.sh 2ndJob.sh 1st Job - FTP files from Mainframe to Unix using the following commands at the tail of... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

5. Shell Programming and Scripting

Difference between calling the sub scripts

What is the difference between calling the sub scripts of below two line. /home/scripts/devdb.sh . /home/scripts/devdb.sh sh /home/scripts/devdb.sh We are using the suse 2.0 version (4 Replies)
Discussion started by: kingganesh04
4 Replies

6. Solaris

difference in calling shell scripts

Hi I am getting some errors when i am running the shell script using the following syntax: >abc.sh but the same script works fine with the following syntax: >sh abc.sh wats the difference in both....please help thanks in advance. (6 Replies)
Discussion started by: arpit_narula
6 Replies

7. Shell Programming and Scripting

Issue calling scripts through CRON.

I have the following cron job in the crontab. #! /bin/bash 25 15 * * 1-5 /export/home/svittala/scripts/scpt1.sh >/dev/null 2>&1. The problem that I am facing is - the scpt1.sh can be executed manually. But, it is not executing through CRON. Not sure what's the issue. Any hints?. Thanks.... (5 Replies)
Discussion started by: vskr72
5 Replies

8. Shell Programming and Scripting

any possible solution on sql calling scripts

hi all, i have a function which will take i/p as a ddl sctipt as i/p and execute it, let function execute_sql { db_var="$1" v_cnt=`sqlplus -s XXXXX/XXXXX@aXXX << ENDSQL | sed -e "s/Connected\.//" -e "/^$/d" set pagesize 0 feedback off verify off heading off echo off serveroutput on size... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

9. Shell Programming and Scripting

script calling other scripts hangs

I have a script that calls several other scripts in a specified order: # Loop over actions in specified order (STOP_ORDER or START_ORDER) and build and evaluate commands for command in $(eval print '$'${action}_ORDER) do printf "`date`\tExecuting ${action}_${command} = `eval print... (1 Reply)
Discussion started by: rein
1 Replies

10. Shell Programming and Scripting

Calling functions in scripts directly

Hi, I have a menu driven script that does various tasks, I want to be able to call functions directly from within other unix scripts from my menu script. Is this possible? (12 Replies)
Discussion started by: LiquidChild
12 Replies
Login or Register to Ask a Question