The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Restart script based on MD5sum Bakes Shell Programming and Scripting 6 01-02-2009 11:32 AM
Process based code vs. Thread based code rkalyankumar UNIX for Advanced & Expert Users 3 09-09-2008 09:55 AM
Restart process brendan76 SuSE 3 02-26-2008 12:43 PM
need help to write script to check the process health and automatically restart it dragondad Shell Programming and Scripting 1 10-31-2006 06:16 PM
suspend/restart a process in shell script daneensign Shell Programming and Scripting 1 02-14-2006 12:43 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2009
e-l-diablo e-l-diablo is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 8
restart process based on file

Hi all.
I do have a script "startApp.sh" (app result is a file /opt/extract/appextract.txt)

I have no problems with stopping app

Code:
var1=`ps -ef | grep -v grep | grep MyApp | awk '{print $2}'`
kill -9 $var1
What I want to achieve is:

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.

Last edited by zaxxon; 07-21-2009 at 07:15 AM.. Reason: code tags
  #2 (permalink)  
Old 07-21-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Script could look like:

Code:
#!/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
  #3 (permalink)  
Old 07-21-2009
e-l-diablo e-l-diablo is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 8
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)
  #4 (permalink)  
Old 08-12-2009
e-l-diablo e-l-diablo is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 8
Hi again. After testing it does not work

What i have done:
I have script called startMe.sh. It starts app and should kill when file in specific directory exists.
Code:
#!/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
killapp.sh looks like
Code:
var1=`ps -ef | grep -v grep | grep java | grep username | awk '{print $2}'`
kill -9 $var1
Where am i doing something wrong?
  #5 (permalink)  
Old 08-12-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
No idea if this is a typo:

Code:
... *that removes restart file if exist
Comments should start with a # nor a *.

Is ./startApp.sh touching that flag file?
Also what is not working? A bit more details could help, ty.
  #6 (permalink)  
Old 08-12-2009
e-l-diablo e-l-diablo is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 8
Hi.
Code:
*that removes restart file if exist
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)
Code:
./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.
  #7 (permalink)  
Old 08-12-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
So your script ./startApp.sh seems to have a problem.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0