LinuxQuestions.org
Review your favorite Linux distribution.
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 07-22-2010, 01:55 PM   #1
sun81
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Rep: Reputation: 0
Shell script to delete file if a pattern is found and restart servers


Hi,

I have requirement to delete some log files from a directory if a string
"deletethisfile" is found.
Then restart the application servers.

1. Search for the string “deletethisfile” in server.log file under a directory, If found
2. Stop that particular server.
3. Delete the log file
4. Restart the server.

Thanks for your help in advance..
 
Old 07-22-2010, 02:07 PM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Code:
Pseudo-shell-code:

if grep -q "deletethisfile" $LOGFILE; then
    /etc/init.d/$SERVICE stop
    rm -f $LOGFILE
    /etc/init.d/$SERVICE start
fi
Quite straight-forward...
 
Old 07-22-2010, 03:24 PM   #3
sun81
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Zirias

Thanks for the quick reply..
 
  


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
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 05:58 AM
delete multiple lines from file using shell script mech123 Linux - Newbie 4 06-09-2010 05:04 AM
Shell Script to Delete part text of a line if pattern matches harsha1980 Programming 36 04-16-2010 04:36 AM
Need a bash shell script which will delete lines from file scjohnie Linux - Newbie 1 09-13-2008 09:51 PM


All times are GMT -5. The time now is 01:08 AM.

Main Menu
Advertisement
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