I start app, app is doing some extraction, after extraction is done i would like to stop app (kill app if/when) wait some time (~ 30 sec. different processes/scripts taking place) and start app again (until next extract)
I will try to be more schematic
start App
app is running, doing stuff, and creates a file
when file is created I have to stopApp
wait ~30sec
start app
Could you please guide me how to create some script that will be in "constant loop" or a service and will watch for that file, if exist do somethinh (kill my app)
thank you very much
e-l-diablo
Use CODE-tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc., ty.
#!/bin/sh
./app start
while :; do
sleep 1 # just to give it short breaks
if [[ -e /<path-to-your-output-file>/filename ]]; then
./app stop
sleep 30
break
fi
done
./app start
exit 0
perfect.
Wht I dod not think about that.
That is what I was searching for. I will give a try and let you know if it works as it should (there are more scripts in that process)
very, very much thank you (i will do some modifications, i already see some options)
What i have done:
I have script called startMe.sh. It starts app and should kill when file in specific directory exists.
#!/bin/sh
rm /opt/tmp/restart.txt *that removes restart file if exist
./startApp.sh
while :; do
if [[ -e /opt/tmp/restart.txt ]]; then
./killapp.sh
sleep 30
break
fi
done
./startApp.sh
exit 0
That was FYI
Few more details. I am running Solaris 10 on SUN x4450 box (really nice work horse) with 128GB RAM.
when I run ./startApp.sh all works as it should: my application starts
and i get messages (all the time)
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
./startApp.sh: [[: not found
when i place killapp.txt under /opt/tmp nothing, just nothing. That is strange becaus in theory should work.
#!/bin/sh
rm /opt/tmp/restart.txt
./startTOMCAT.sh
while :; do
if [[ -e /opt/tmp/restart.txt ]]; then
./killapp.sh
sleep 30
break
fi
done
./startTOMCAT.sh
exit 0
That is what i do not understand. It shouldd work
my default is bash (i like it)
I removed "[[" and left "[". It is better now.
that is the output
/opt/tmp/restart.txt: No such file or directory
Using CATALINA_BASE: /opt/apps/tomcat
Using CATALINA_HOME: /opt/apps/tomcat
Using CATALINA_TMPDIR: /opt/apps/tomcat/temp
Using JRE_HOME: /opt/java/1.6/
./startApp.sh: test: argument expected
That is what i get. I have just copied restart.txt to /opt/tmp/ and app is still working - no restart.
You are THE MAN. I always used #!/bin/sh or #!/bin/csh and had never problems before
That fixed it. Additionally I had to change that sctipt (small loop) because it did the stop/start/restart 1only. If i want to doit more than 1 it will not work. I have to call startApp.sh from startApp.sh (i know i should not)
startApp.sh
#!/bin/bash
rm /opt/tmp/restart.txt
./startTOMCAT.sh
while :; do
if [ -e /opt/tmp/restart.txt ]; then
./killapp.sh
rm /opt/tmp/restart.txt
sleep 30
break
fi
done
./startApp.sh
exit 0