Download your favorite Linux distribution at LQ ISO.
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 06-04-2009, 04:55 PM   #1
Registered: Oct 2003
Posts: 134

Rep: Reputation: 15
Need help with a script


I need help writing a script to for certain error, if exist restart a certain service.

Where do I start??


Old 06-04-2009, 04:58 PM   #2
Senior Member
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
You could start with some details that will help us figure out what you're after.

1) What language (bash, perl, something else) are you using?
2) What error?
3) Does the service being checked log its errors?
4) On what interval do you want to check (creating a cron script vs. a daemon)?
Old 06-04-2009, 05:08 PM   #3
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
I would like to write it in bash. I would like to check errors like Sendmail and cups. So far, there are no logs why these services stopped, but leaves behind a PID id. Once I have the script, I set up in the crontab to check every 5 mins or so.

Thank you.

Old 06-04-2009, 05:10 PM   #4
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
There should be a log of it, they should be in /var/log
Old 06-05-2009, 01:31 AM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,418

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
As mentioned, they do (usually) have a log file.
Also, /etc/rc.d usually has the system service startup scripts. All you have to do is call them.
Old 06-05-2009, 01:37 AM   #6
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The script that starts the service may take a "status" argument that would allow you to determine easily whether the service is running or not.

It may be more useful to determine to determine the problem leading to the services aborting and fix that problem.


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
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 04:29 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 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