Executing multiple scripts using if condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing multiple scripts using if condition
# 1  
Old 09-08-2015
Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script.

i tried like below :
Code:
cd lock
 if [ $(ls -ltr | grep -q exitup) -eq 0 ]; then 
rm exitup
 if [ $(Appl_Monitor | echo $?) -ne 110 ]; then 
kb_shutdown 
kb_startup 
if [ $(ls -ltr | grep -q exitup) - eq 0 ]; then
rm exitup
 if [ $(Appl_Monitor | echo $?) -eq 110 ]; then
 echo " kb app is fine  $(ls -ltr | Appli_Monitor | echo $?) | mailx -s "KB App " abc@gmail.com 
else 
echo " Warning KB app is not running   $(ls -ltr | Appli_Monitor | echo $?) | mailx -s "KB App " abc@gmail.com
 fi 
fi
 fi 
fi

where Appl_Monitor , kb_shutdown ,kb_startup are scripts .
# 2  
Old 09-08-2015
There are a lot of strange constructs in your script. So many that I can't quite figure out what you're trying to do.

Please explain in English what each of these scripts are supposed to do, what output and exit codes each of these scripts produce, and the conditions under which each script is supposed to be invoked.
# 3  
Old 09-08-2015
i want to check a file called "exitup" in the directory called "locks" and if it presents then i need tp remove it and then i need to run a script called "Appl_monitor" and its exit status should be 110. if the exit status is other than 110 then i need to stop the application using a script called "kb_shutdown" and then start the application using a script called "kb_startup".

once it done again i need to check for the file "exitup" in the locks directory,if there need to remove it and then need to check the exit status of script called "Appl_Monitor".if it equals to 110 send mail that app is fine or else send a mail that app is not fine.

this is my requirement.
# 4  
Old 09-08-2015
You didn't specify what operating system or shell you're using, but the following should work with any shell based on Bourne shell syntax (including, but not limited to, ash, bash, dash, ksh, and zsh):
Code:
#!/bin/ksh
cd locks
if [ -e exitup ]
then	rm exitup
	Appl_monitor
	if [ $? -ne 110 ]
	then	kb_shutdown
		kb_startup
	fi
fi
if [ -e exitup ]
then	rm exitup
	Appl_monitor
	if [ $? -eq 110 ]
	then	subject="KB app is fine"
	else	subject="KB app is not fine"
	fi
	mailx -s "$subject" abc@gmail.com < /dev/null
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script if condition not executing

issue is with .txt files (7 Replies)
Discussion started by: anil529
7 Replies

2. Shell Programming and Scripting

Executing multiple child scripts - failing

Hi Folks - Happy Thursday! I have a need where I have Parent/Control script that calls multiple child scripts. The problem is, after the first child script is executed, it fails to move to the next script. I assume it's due to my script exit? For instance, in batch to return to the parent... (12 Replies)
Discussion started by: SIMMS7400
12 Replies

3. Shell Programming and Scripting

Default shell for executing scripts

Hi there, And happy new year to everyone. I was wondering how is set the default shell for executing scripts. I mean when the first line of a script file is not #!/bin/bashThen what shell will be used to execute the script? I thought the script file would be parsed using the current shell... (6 Replies)
Discussion started by: chebarbudo
6 Replies

4. Shell Programming and Scripting

Executing all scripts in /DIR except one

First i need to find all scripts directly under /DIR that end with ".sh" extension except "noallow.sh". That can be done with: find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh" Now i want to run all the files output from the previous command. The following code: for filename in... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

5. Shell Programming and Scripting

Executing several bash scripts in succession

Hi, I am new to shell programming. I am trying to automate setting up a network using several scripts. Some of the scripts require to reboot in order to continue with the setup. Is it possible to enter another script as soon as the system reboots. Also, if the last line of the script is bash... (7 Replies)
Discussion started by: fantasyland
7 Replies

6. UNIX for Dummies Questions & Answers

Executing scripts in back ground

Hi, Test1.ksh #! /bin/ksh for i in $* do #echo "$i" ksh test2.ksh $i & done test2.ksh #! /bin/ksh sleep 5s echo "From Test 1 ==> $1" exit 0; I am executing as follows: ksh test1.ksh a b c (10 Replies)
Discussion started by: risshanth
10 Replies

7. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

8. UNIX for Dummies Questions & Answers

Executing Shell Scripts

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try... (1 Reply)
Discussion started by: BuyoCat
1 Replies

9. UNIX for Advanced & Expert Users

executing perl scripts

Does anybody experiencing this same problem? I am using IRIX64 ver 6.5 at work. I wrote some Perl scripts and to execute it. First I try to put the Perl script at: /$HOME/bin/perlscript then I set the correct executable 755 right to the file I make sure the PATH to the executable... (2 Replies)
Discussion started by: vtran4270
2 Replies

10. UNIX for Dummies Questions & Answers

Running scripts with condition

I have two scripts: SCR1 which takes between 5 seconds to 15 minutes and needs to be run every 23 minutes. SCR2 which needs to be run every 5 minutes but only if SCR1 is not running at that moment. How can I do this task? Best Regards /Hamid (3 Replies)
Discussion started by: Hamid Afsharazad
3 Replies
Login or Register to Ask a Question