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