LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-17-2011, 12:06 AM   #1
tulsi
Member
 
Registered: Aug 2009
Location: Chennai
Posts: 54

Rep: Reputation: 15
shell script problem


Hi Guys,

I write a shell script,its shown in below,


#!/bin/bash

ps -ef | grep -v grep | grep "./server"

if [ $? -eq 1 ]

then


echo " not working"


cd /home/server

nohup ./server > /dev/null 2>&1&


else

echo "its working fine"

fi


when the "server" was stop and i ran the script, its run but after sometime i greped out ps -ef | grep /.server , this process was not running,i am doing couple times, but same result. can you suggest me any problem in the script.

Thanks
 
Old 03-17-2011, 12:45 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
First of all, edit your post and put the code in code tags, thanks.

As far as the actual problem, change ./server to server in your grep statement. It should do the trick... If not, let me know.

Josh
 
Old 03-17-2011, 01:03 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Your script will include the grep line which contains the pattern you are looking for.
Code:
ps -ef | grep server
jschiwal  2714 21717  0 00:44 pts/4    00:00:00 grep server
jschiwal  2786  2535  0 Mar14 ?        00:00:00 kwrapper4 ksmserver
...
You will have other false matches as well.

It would probably be better to check services using it's startup script with a "status" option. If this is a server you wrote yourself. A service usually creates a .pid file the contents of which is the PID of the process. A shell wrapper could echo $$ to a file, and you could use that files value.


You could also use `pidof' to return the pid of a named command.
Code:
jschiwal@qosmio:~> ps -p $(pidof caliber) >/dev/null 2>&1 && echo OK || echo FAILED
FAILED
jschiwal@qosmio:~> ps -p $(pidof calibre) >/dev/null 2>&1 && echo OK || echo FAILED
OK
 
Old 03-17-2011, 02:19 AM   #4
tulsi
Member
 
Registered: Aug 2009
Location: Chennai
Posts: 54

Original Poster
Rep: Reputation: 15
shell script problem

first of all thanks for your replies,

can you explain pidof command ...

Last edited by tulsi; 03-17-2011 at 02:22 AM.
 
Old 03-17-2011, 02:41 AM   #5
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
All pidof does is returns the PID of the process you pass to the command.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
[SOLVED] problem with a shell script lamou23 Linux - General 4 07-07-2010 06:40 PM
problem with shell script john smith Linux - Newbie 4 03-14-2009 06:03 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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