Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-14-2008, 04:33 PM   #1
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

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
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,863

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
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
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.


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 15 06-21-2016 05:59 PM
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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:50 AM.

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