LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 12-07-2015, 02:31 AM   #1
manish007raut@gmail.com
LQ Newbie
 
Registered: Dec 2015
Location: India
Posts: 8

Rep: Reputation: Disabled
Lightbulb Shell script that can check the status of service, if online then only it should run


I am new in this filed and have very less knowledge. Could someone please help me making a Shell script that can check the status of service, if the service is online then only it should run and should wait till the service status "Online". Thanks in advance.


will explain the scenario(if any suggestion in below scenario , u r most welcome:-
1. Want my script to run at last after every service has been started.
2. for that will call my script from local.rc.
3. So the script for which i needed your help will be checking one of the service from init.d, and iff the service status is online then only it should run , otherwise it should wait for it get online and then it should run.

Last edited by manish007raut@gmail.com; 12-09-2015 at 04:53 AM. Reason: New here, got some good suggestions about how to ask questions. :)
 
Old 12-07-2015, 04:35 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by manish007raut@gmail.com View Post
Making a Shell script that can check the status of service, if online then only it should run and should wait till the service status "Online".
Hello Manish, since you introduced yourself as "Working as an IT Engineer" you should be able to design the functionality, create the script yourself and post it here for comments. So by all means have a go at it. No need to ask for handouts (or ask questions that don't start with "Could you please help" and don't end with a question mark).
 
1 members found this post helpful.
Old 12-07-2015, 05:33 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Depends on the distro, too. SystemV- (or is it Upstart- ?) based distros use the service command to check the status, systemd-based ones use the systemctl command, and there are others which have their own way of doing this.

To get you going:
Code:
if ! service httpd status >/dev/null 2>&1
then service httpd start
fi
 
Old 12-08-2015, 07:48 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by manish007raut@gmail.com View Post
Making a Shell script that can check the status of service, if online then only it should run and should wait till the service status "Online". Thanks in advance.
Great...so since you're making it, why don't you share it with us? Or are you having a problem?? If so, we can (and will) only help you if you post what YOU have written/tried on your own. We ARE NOT going to write shell scripts for you...especially since you're an "IT Engineer". Read the "Question Guidelines" link in my posting signature.
 
Old 12-10-2015, 02:49 AM   #5
manish007raut@gmail.com
LQ Newbie
 
Registered: Dec 2015
Location: India
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hey please reply, i modified my question.
 
Old 12-10-2015, 03:08 AM   #6
manish007raut@gmail.com
LQ Newbie
 
Registered: Dec 2015
Location: India
Posts: 8

Original Poster
Rep: Reputation: Disabled
I am new in this filed and have very less knowledge. Could someone please help me making a Shell script that can check the status of service, if the service is online then only it should run and should wait till the service status "Online". Thanks in advance.


will explain the scenario(if any suggestion in below scenario , u r most welcome:-
1. Want my script to run at last after every service has been started.
2. for that will call my script from local.rc.
3. So the script for which i needed your help will be checking one of the service from init.d, and iff the service status is online then only it should run , otherwise it should wait for it get online and then it should run.
 
Old 12-10-2015, 03:37 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
the answer is the same: what have you done so far, where did you stuck?
 
Old 12-10-2015, 08:27 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by manish007raut@gmail.com
Hey please reply, i modified my question.
...which is frowned upon, since editing your posts makes things harder to follow.
Quote:
Originally Posted by manish007raut@gmail.com View Post
I am new in this filed and have very less knowledge. Could someone please help me making a Shell script that can check the status of service, if the service is online then only it should run and should wait till the service status "Online". Thanks in advance.

will explain the scenario(if any suggestion in below scenario , u r most welcome:-
1. Want my script to run at last after every service has been started.
2. for that will call my script from local.rc.
3. So the script for which i needed your help will be checking one of the service from init.d, and iff the service status is online then only it should run , otherwise it should wait for it get online and then it should run.
And again, we all understand what you WANT...what you haven't shown us is ANY effort on your part to actually DO IT. Again, WE WILL NOT write scripts for you, period. We will gladly help you, but you have to post what you have done.

There are tens of thousands of very easily-found scripting tutorials (with examples), you can find with a brief Google search. Unless you actually start doing work, you'll always be 'new with very less knowledge'. Start doing your own work...post what you do/try, and tell us where you're stuck, and you can get help. Otherwise, just re-posting the same question asking for a handout still won't get you anything.
 
Old 12-10-2015, 02:13 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by manish007raut@gmail.com View Post
I am new in this filed and have very less knowledge.
Have you read any simple BASH shell tutorials? (Hint: search LQ.)


Quote:
Originally Posted by manish007raut@gmail.com View Post
Could someone please help me making a Shell script that can check the status of service, if the service is online then only it should run and should wait till the service status "Online".
- What specific service are you talking about?
- What is the complete and proper command to check if the service is available?
- What is the full output of the previous command?
- What is the full output of the previous command if it is offline or errors out for other reasons?
 
Old 12-15-2015, 07:23 AM   #10
manish007raut@gmail.com
LQ Newbie
 
Registered: Dec 2015
Location: India
Posts: 8

Original Poster
Rep: Reputation: Disabled
- Actually i am working on bpm services(i have one product installed on my machine)
-I will be writing a script that will be called from local.rc, so first i have to check weather the service is online or not, for that will use command "/etc/init.d/bpm-server status" and after that "echo $?". if the output of echo $? = 1 , then the service is online, otherwise offline(2 for offline).
- So its not end here, i have to wait for the service to get online, so will have to use sleep, so sleep till echo $? = 1 . and when it satisfies this condition then only proceed for further script.

- so please suggest me how it can be done!
Thanks in advance.
 
Old 12-15-2015, 09:04 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by manish007raut@gmail.com View Post
- Actually i am working on bpm services(i have one product installed on my machine)
-I will be writing a script that will be called from local.rc, so first i have to check weather the service is online or not, for that will use command "/etc/init.d/bpm-server status" and after that "echo $?". if the output of echo $? = 1 , then the service is online, otherwise offline(2 for offline).
- So its not end here, i have to wait for the service to get online, so will have to use sleep, so sleep till echo $? = 1 . and when it satisfies this condition then only proceed for further script.

- so please suggest me how it can be done!
You just SAID how it can be done. You stated the steps; AGAIN, YOU need to show us what YOU have written/tried on your own. We STILL will not write this for you, especially with the thousands upon thousands of bash-scripting tutorials you can easily find with a brief search...including one in my own posting signature. Since you say YOU will be writing this script, then show us what you have accomplished, and tell us where you're stuck.

Otherwise, see ANY of the many easily-found examples of rc scripts you can find with a brief Google search, and use them to get you going.
 
Old 12-15-2015, 09:04 AM   #12
manish007raut@gmail.com
LQ Newbie
 
Registered: Dec 2015
Location: India
Posts: 8

Original Poster
Rep: Reputation: Disabled
Till now what i have done is as follows:-

/etc/init.d/bpm-server status
if [ "$?" == 1 ]; then
files=`find / -type f -perm 0777`
for f in $files
do
echo "file :"$f
chmod o-w $f
done
else
sleep 10m

fi

-I want this script should check seamlessly until the $? = 1, and after that only run the for loop.
 
Old 12-15-2015, 01:46 PM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,790

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
What's the following for?
Code:
files=`find / -type f -perm 0777`
for f in $files
do
echo "file :"$f
chmod o-w $f
done
I am missing any relation to your requirement.

Here is something that fits your requirement
Code:
# run a service check; if the exit status is not 0 (0=success) then ...
/etc/init.d/bpm-server status
if [ $? -ne 0 ]
then
  # start the service
  ...
  # after a sleep check the service again
  ...
fi
The ... need to be implemented.
 
Old 12-15-2015, 03:11 PM   #14
chuckachup
LQ Newbie
 
Registered: Aug 2013
Posts: 17

Rep: Reputation: Disabled
Do the experienced people here always talk to everyone like this?

Where's the friendliest Linux Newbie site with the most handholding.

I never saw a rule saying Can you please Help is disallowed, or question marks.

Sure there are hundreds of tutes on the web, but I've followed some random advice in the last week that turned out to be a bad way to do somethings, so it might be more helpful if you actually point us towards the trusted sources, rather than......

I don't want to put it into words but I have some pretty strong feelings about the way people are talking to each other in here

Am sure that feelings are not encouraged but sorry, we are all human.
 
Old 12-16-2015, 07:41 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by chuckachup View Post
Do the experienced people here always talk to everyone like this?

Where's the friendliest Linux Newbie site with the most handholding. I never saw a rule saying Can you please Help is disallowed, or question marks.
Read the "Question Guidelines" link in my posting signature, as the OP here was directed to. Hand-holding is fine, and as said, we are ALWAYS happy to help, but asking for a HANDOUT (that is, "I need a script to do xxx"), isn't. Being helpful and friendly is one thing...doing someones job/homework FOR THEM is another.

To put it another way, suppose someone asked you to help them move...then they sat in a chair on the lawn, and watched you load the truck? That's not HELP; help is the person asking doing SOMETHING too.
Quote:
Sure there are hundreds of tutes on the web, but I've followed some random advice in the last week that turned out to be a bad way to do somethings, so it might be more helpful if you actually point us towards the trusted sources, rather than......
...and the 'trusted sources' would be what??? Are you saying that folks here should do Google searches and try EVERYTHING for people who ask, to save them the trouble of actually doing it themselves? And those tutorials work for SOME people, not others. What you have described is a process called 'learning'...trying things, and figuring out what works and what doesn't.
Quote:
I don't want to put it into words but I have some pretty strong feelings about the way people are talking to each other in here Am sure that feelings are not encouraged but sorry, we are all human.
Yes, we are all human...mistakes are part of life. However, showing zero effort of your own is NOT 'being human'...it's being lazy.
 
  


Reply



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 for CPU usage, memory usage, disk partition space and service status reetesh.amity Linux - Server 6 10-12-2015 07:51 PM
Shell Script to check the printer status not sending email pantdk Linux - Server 3 03-20-2015 12:37 AM
how to check in a bash script where the shell is run from nass Slackware 5 10-24-2012 12:35 AM
[SOLVED] write a shell script so that it can run as service/daemon deostroll Programming 10 03-08-2010 10:03 AM
Need to write a shell script which will check the GUI login and retuen the status cod bhsk_08 Linux - General 2 10-14-2008 01:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:43 PM.

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