LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script to delete file if a pattern is found and restart servers (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-delete-file-if-a-pattern-is-found-and-restart-servers-821543/)

sun81 07-22-2010 12:55 PM

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..

zirias 07-22-2010 01:07 PM

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...

sun81 07-22-2010 02:24 PM

Thanks Zirias
 
Thanks for the quick reply..


All times are GMT -5. The time now is 09:44 AM.