I just want to run a script automatically whenever i receive an error called " application failed " .
so i wrote the below script for that , but it is not working .
#!/bin/ksh
DATE=`date +%Y%m%d`
sanity > /home/sanity_logs_$DATE
if [ "$(grep -c 'Application Failed' /home/sanity_logs_$DATE)" -eq 0 ] ; then
echo "False Alarm "| mailx -s "False alarm" abc@gmail.com
rm -f /home/sanity_logs_$DATE
else
{ echo 7; while [1]; do echo c;done;} | start_up
echo " Failure resolved
Below are the processes running
$(sanity) " | mailx -s " Failure resolved " abc@gmail.com
fi
Where "sanity" is the script which monitors the application and " start_up " is the script to start the application.
Once start_up script starts executing first it will ask to select the option " 7" and then it will ask to select the option "c" (many number of times).
please help in me . It is Solaris 5.8 o.s so yes command is not working .
If your script prematurely exits, then how will the clean up part run?
You should look at the trap event and create a trap event for exit.
Then if the script errors out, the trap event gets called and can run.
It can be as simple as this. You will need to check the syntax and make
sure that it works under a variety of circumstances.
#!/bin/ksh
run_exit_function () {
if [ "$(grep -c 'Application Failed' /home/sanity_logs_$DATE)" -eq 0 ] ; then
echo "False Alarm "| mailx -s "False alarm" abc@gmail.com
rm -f /home/sanity_logs_$DATE
else
{ echo 7; while [1]; do echo c;done;} | start_up
echo " Failure resolved
Below are the processes running
$(sanity) " | mailx -s " Failure resolved " abc@gmail.com
fi
}
trap 'run_exit_function' exit
DATE=`date +%Y%m%d`
sanity > /home/sanity_logs_$DATE
But my requirement is to enter multiple inputs . First i need to enter 7 and then i need to enter "c" so may times . so i used while loop as YES command is not working in my O.S.
This is the flow. first i will give 7 as input (only once)and then "c" as input(nearly 30 times) . But the below command is not working ,it is asking for the option 7 to enter .
Can anyone help in this . Any small mistakes like spaces or changing brackets ?/
my concern is that the script is not giving 7 as input to the inside the script while running.
echo 7 is not working ..
---------- Post updated at 10:12 AM ---------- Previous update was at 08:01 AM ----------
first of all the script " start_up " should take option 7 automatically then it should take "c" so many times. When i am running the above script it is not taking option 7 automatically.. that mean " echo 7 " is not working or any small thing i am missing .. i am confused .. please any help ?
counted_loop() { # TIMES CHAR
# Prints TIMES and then loops
# to print CHAR that many TIMES
C=0
start_up<<EOF
$1
$(while [$C -lt $1 ];do echo $2;((C++));done)
EOF
}
### START IT ###
counted_loop 7 c