LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-14-2008, 04:33 PM   #1
damoj
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Rep: Reputation: 0
Script needed to check then restart application processes


Hi All,

I am trying to come up with a script that will do the
following:

1. Overwrites a word in a text file.
2. Then Stops an Apache server running.
3. Then checks the status of the Apache server to make sure it is stopped
4. If it is stopped then it restarts apache server.
5. Then restores the text file to its original state.


I have been looking at using:

1. sed s/$VARIABLE1/"$VARIABLE2"/g conf.txt
2. apachectl stop
3. apachectl status
4. apachectl start
5. sed s/$VARIABLE2/"$VARIABLE1"/g conf.txt



I'm new to shell scripting so I don't know how to tie this together or if I am even using the correct approach.

Any ideas appreciated.
 
Old 04-14-2008, 07:19 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,469

Rep: Reputation: 154Reputation: 154
One piece of logic that you need to add is determining whether apache actually stopped. You need to check the return code of either step 2 or step3 to determine if apache actually stopped. If apache actually stopped then you do steps 4 and 5. However you have not described what you want to do if the apachectl stop command did not work.

------------------
Steve Stites
 
Old 04-15-2008, 02:04 AM   #3
damoj
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks jailbait well spotted.

Ideally I would like the return code of step 3 to confirm Apache is not running and then 1) restart Apache and 2) restore the text file to its restart state.


If the return code indicates Apache has not shutdown I would like it to retry the shutdown once more and if successful the second time then restore the text file to its original state.

If Apache does not shutdown I would still need the text file restored to its original state.

So basically the text file needs to be restored to it original state regardless if Apache shuts down or not.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to check connection (and restart network if down) mac_phil Linux - Networking 10 01-06-2010 05:19 AM
need help to write script to check the process health and automatically restart it dragondad Programming 3 11-01-2006 12:23 PM
Script to restart application services on remote systems vinayhr Programming 3 09-04-2006 12:37 AM
check user processes macie Linux - General 4 11-09-2003 11:57 AM
Monitor and Restart - Bkg Processes? KendersPlace Linux - General 1 02-15-2003 02:27 AM


All times are GMT -5. The time now is 11:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration