Running a unix script(which is calling another script inside that) in background

Hi all,

I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously.
for Keeping this script as background how is it possible.?????
The Script A is having scp command and ScriptB is using SSH command and Script A is continously watching for events in ServerA. SO for running this continous looop which is using all these 3 scripts what is the method. I have tried nohup . but in that all the 3 scripts i have to do nohup ??? Crontab ?? i have tried but was not able to do the required result. i m using expect for sending password in scp and if i execute in background it is exiting and scripts are not functioning.

Please Help me out for solving this issue Unix Experts.

Thanking you all in advance

Regards,

Rohith G

Can u post your requirements and sample script . To help better we need to understand logic better.

Hi ,

I have one main script called script1.sh which contains the cotennts below. this script wil search for the existence of files in a particular directory and if one file is finidin it wil send to another server . this is the basic functionality
the script1.sh is given below

#Al the directiory locations wil be mentinedin the first

# Trace output function
trace ()
{
if [ $TRACE ]
then
DATE=`date +"%Y-%m-%d %X"`
echo "$DATE: $1" >> $TRACEFILE
fi
}

trace "Script $0 started"

# First find all alarm files to import at start
FILES="`find $ALARM_FILES_DIR -type f`"

# Loop forever and import files
while [ true ]
do
loop=`expr $loop + 1`

# cat the files to a text file
if [ "$FILES" != "" ]
then
FILES_SORTED="`ls -rt $FILES`"
trace "Alarm files to import:\n$FILES_SORTED"

for i in $FILES_SORTED
do
  cat $i>export1.txt

username=***
password=***

expect -c "
          \# exp_internal 1 \# uncomment for debugging

spawn /usr/bin/scp export1.txt ***@ipaddress:/location

        expect \{
            "\*password:*" \{ send $password\\r\\n; interact \}
            eof \{ exit \}

          \}
          exit
         "

/export/home/netcool/rohith/script.sh
rm -rf export1.txt

echo
done

LATEST="$i"
SENDHB=false

else
trace "No new alarm files to import"
SENDHB=true
fi

trace "Latest alarm file imported: $LATEST"

#
# If the latest file sent still exists then find newer files, otherwise find all files
if [ -f "$LATEST" ]
then
FILES="`find $ALARM_FILES_DIR -newer $LATEST -type f`"
else
FILES="`find $ALARM_FILES_DIR -type f`"
fi
# Modify sleep time (in seconds) as needed below
sleep 2

done

THIS SCRIPT WIL CALL THE SECOND SCRIPT CALLED SCRIPT.SH contents given below since expect cant used inside the first script i hav given like dat in dif script i mean /usr/bin/expect -f

#!/usr/local/bin/expect -f
spawn ssh ***@ipaddrss 'location/ssh.sh'
expect "password:"
send "netcool\n"
interact

This wil call another script in server2 called ssh.sh contents are given below

#!/bin/sh
cat export1.txt >> export.txt
rm export1.txt

I need to execute all these 3 scripts in crontab for copyn the files automatically.

I am really a beginner in scripting. I know some logical mismatch may be der . PLease correct me and help me out for solving this.

REgards,

ROhith G