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.

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

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

if test $CAPACITY -gt $MAXCAP; then
/full/path/to /archive.sh &

You should add

wait

as the last line of your script - it will wait for the child processes you are creating. Otherwise those processes will be terminated.

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:

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

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

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.

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 :slight_smile:

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

What does your code look like now?

Hi all
OK, these are the two scripts
the first one is scheduled in cron to run every 15 mins

#!/bin/ksh
#
# Solaris Monitor File Systems Script
# Purpose: Monitors the size of file systems.
# Dependencies: log.dat -  Contains which file
# systems to monitor and how large they can be
#*********************************************************
# The directory this script resides in
ADMINDIR=/usr/local/bin
# 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
exec /usr/local/bin/autoarch.sh &
fi
done < $ADMINDIR/log.dat
echo log space monitoring script, logmon.sh ran on `date` >>/usr/local/bin/archive.log
exit 0
EOF
wait
fi

the second that is called from logmon.sh is

#!/bin/ksh
#
# Solaris BRArchive script
# Purpose: Archives log files from /oracle/SID/oraarch when space reaches 'x' percent.
# Usage: Called from logmon.sh 
#*********************************************************
# The directory this script resides in
ADMINDIR=/usr/local/bin
exec /sapmnt/SID/exe/brarchive -c force -p /oracle/SID/102_64/dbs/initSID.sap -save_delete -d util_file -r /oracle/SID/102_64/dbs/initSID.utl -k no -l E

When I run logmon.sh from the command line when filespace is ok I get this result

./logmon.sh
5
21
/oracle/SID/oraarch
%

it finishes and returns to the prompt

when I run it when the filespace is over the checkmark it does this

./logmon.sh
44
21
/oracle/SID/oraarch
% BR0002I BRARCHIVE 7.00 (40)
BR0006I Start of offline redo log processing: aejbungh.svd 2012-07-27 14.15.35
BR0484I BRARCHIVE log file: /oracle/SID/saparch/aejbungh.svd
BR0477I Oracle pfile /oracle/SID/102_64/dbs/initSID.ora created from spfile /oracle/SID1/102_64/dbs/spfileSID.ora
BR0280I BRARCHIVE time stamp: 2012-07-27 14.15.36
BR0008I Offline redo log processing for database instance: SID
BR0009I BRARCHIVE action ID: aejbungh
BR0010I BRARCHIVE function ID: svd
BR0048I Archive function: save_delete
BR0011I 34 offline redo log files found for processing, total size 3078.554 MB
BR0130I Backup device type: util_file
BR0109I Files will be saved by backup utility
BR0134I Unattended mode with 'force' active - no operator confirmation allowed
BR0280I BRARCHIVE time stamp: 2012-07-27 14.15.36
BR0229I Calling backup utility with function 'backup'...
BR0278I Command output of '/usr/sap/SID/SYS/exe/run/backint -u SID1 -f backup -i /oracle/SID/saparch/.aejbungh.lst -t file -p /oracle/SID/102_64/dbs/initSID.utl -c':
BR0280I BRARCHIVE time stamp: 2012-07-27 14.16.28
#ARCHIVE.. /oracle/SID/oraarch/SIDarch1_2308_782194798.dbf
#SAVED.... 1343412938

etc until its completed archiving and deleting all the files, but then the script does not exit until I press Enter.
when I run the ./autoarch.sh script from command line when there are no files to archive I get this

% ./autoarch.sh
BR0002I BRARCHIVE 7.00 (40)
BR0006I Start of offline redo log processing: aejbttex.svd 2012-07-27 10.29.39
BR0484I BRARCHIVE log file: /oracle/SID/saparch/aejbttex.svd
BR0477I Oracle pfile /oracle/SID/102_64/dbs/initSID.ora created from spfile /oracle/SID/102_64/dbs/spfileSID.ora
BR0013W No offline redo log files found for processing
BR0007I End of offline redo log processing: aejbttex.svd 2012-07-27 10.29.40
BR0280I BRARCHIVE time stamp: 2012-07-27 10.29.40
BR0004I BRARCHIVE completed successfully with warnings

and it goes back to the prompt
when I run autoarch when there are files to be archived, it runs, archives them then exits to prompt...
where am I going wrong!!
thanks in advance
alison

The exec finishes the current Shell and starts a new Shell. No command after that exec will run.

Perhaps you meant:

nohup /usr/local/bin/autoarch.sh &