Sponsored Content
Top Forums Shell Programming and Scripting Running a unix script(which is calling another script inside that) in background Post 302368902 by rohithji on Friday 6th of November 2009 12:52:57 AM
Old 11-06-2009
Running a unix script(which is calling another script inside that) in background

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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling a C executable from inside a Perl script

here's the Perl code snippet... how can i call my C executable 'porter-stemmer' and pass it $1 as an argument? Thanks for the help! # Read through the original topic set, and modify based on the current # pre-processing options while (<TOPIC_ORIG>) { # Run pre-processing over only the... (3 Replies)
Discussion started by: mark_nsx
3 Replies

2. Shell Programming and Scripting

differences in calling another script inside script

Hello, we can call the script inside another script. like method 1) content of test.sh ######## . test2.sh ####### method 2) content of test.sh ######## test2.sh ####### What is the difference here in both samples calling test2.sh?? i mean calling with ". " and calling... (1 Reply)
Discussion started by: balareddy
1 Replies

3. UNIX for Dummies Questions & Answers

Running the Script in Background.

Gurus, Pls. help on this to run the script in background. I have a script to run the informatica workflows using PMCMD in script. Say the script name is test.sh & Parameters to the script is Y Y Y Y The no of parameters to the bove script is 4. all are going to be a flags. Each flag will... (2 Replies)
Discussion started by: prabhutkl
2 Replies

4. UNIX for Advanced & Expert Users

Running script in background

When I run the following snippet in background #!/bin/ksh while do echo "$i" sleep 10 i=`expr $i + 1` done My job got stopped and it says like + Stopped (SIGTTOU) ex1 & I did "stty tostop" as suggested in many of the post but still not working... (3 Replies)
Discussion started by: shahnazurs
3 Replies

5. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

6. Shell Programming and Scripting

running the script in background

I have a script called startWebLogic.sh which I was running in the background but the problem is which I used the command :- ps -elf | grep "startWebLogic.sh" | grep -v grep to find the process id but I was unable to find the process id for this script and when I checked from the front end the... (3 Replies)
Discussion started by: maitree
3 Replies

7. Shell Programming and Scripting

Problem in calling a script inside a script

Hi team, I have a script in different folder. Now i want to call that script and execute that script from that path alone. My code is #!/bin/bash wname=yahoo PATH='/opt/IBM' wac=`/usr/bin/ls $PATH | /usr/bin/grep "$wname"` STOP=`/usr/bin/find $PATH/$wac -type f -name "stop.sh"`... (8 Replies)
Discussion started by: natraj005
8 Replies

8. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

9. Shell Programming and Scripting

Calling one script inside another

Hi, I am calling a script log.sh from output.sh. Log.sh has below pice of code: IFILE=/home/home1/Report1.csv if awk -F, '$6==0 && $7==0{exit 1}' ${IFILE} then awk -F, ' BEGIN{ c=split("1,6,2,3,4,5,6", col) print "To: abc@gmail.com" print "Subject: Error... (2 Replies)
Discussion started by: Vivekit82
2 Replies

10. Shell Programming and Scripting

Running script in background

Hi, I wrote a KSH script and running it on HP-UX machine I am running one script in background. My script is at location $HOME/myScript/test/background_sh When I view my script in background with psu commend > psu | grep background_sh I see following output UID PID PPID C ... (1 Reply)
Discussion started by: vaibhav
1 Replies
BZEXE(1)						      General Commands Manual							  BZEXE(1)

NAME
bzexe - compress executable files in place SYNOPSIS
bzexe [ name ... ] DESCRIPTION
The bzexe utility allows you to compress executables in place and have them automatically uncompress and execute when you run them (at a penalty in performance). For example if you execute ``bzexe /bin/cat'' it will create the following two files: -r-xr-xr-x 1 root bin 9644 Feb 11 11:16 /bin/cat -r-xr-xr-x 1 bin bin 24576 Nov 23 13:21 /bin/cat~ /bin/cat~ is the original file and /bin/cat is the self-uncompressing executable file. You can remove /bin/cat~ once you are sure that /bin/cat works properly. This utility is most useful on systems with very small disks. OPTIONS
-d Decompress the given executables instead of compressing them. SEE ALSO
bzip2(1), znew(1), zmore(1), zcmp(1), zforce(1) CAVEATS
The compressed executable is a shell script. This may create some security holes. In particular, the compressed executable relies on the PATH environment variable to find gzip and some other utilities (tail, chmod, ln, sleep). BUGS
bzexe attempts to retain the original file attributes on the compressed executable, but you may have to fix them manually in some cases, using chmod or chown. BZEXE(1)
All times are GMT -4. The time now is 04:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy