Help answer threads with 0 replies.
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 07-22-2010, 01:55 PM   #1
LQ Newbie
Registered: Jul 2010
Posts: 2

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


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
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59

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

Original Poster
Rep: Reputation: 0
Thanks Zirias

Thanks for the quick 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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:54 PM.

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
Open Source Consulting | Domain Registration