LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-23-2012, 01:46 AM   #1
greenworld
LQ Newbie
 
Registered: Dec 2011
Posts: 19

Rep: Reputation: Disabled
Need some SHELL commands


Hi,

How can i find found following process status. Process is Enabled or disabled using shell script. if its currently running set "1" else "0"

EX : /etc/init.d/sshd status
openssh-daemon (pid 3465) is running...


SSH,
FTP,
SMTP,
POP3, and
QMAIL, -Number mail's in queue.
-----------------------------------------------------
i have already created shell script. but its showing correct status or not. i can not find out.
SSH, #netstat -ta | grep ESTABLISHED | grep ssh
FTP, # netstat -a | grep ESTABLISHED | grep ftp
SMTP, # netstat -anp | grep ":25 " | grep LISTEN
POP3, # netstat -anp | grep ":110 " | grep LISTEN

or any other commands available.

i m waiting for reply with hopeful

Thank you,
 
Old 01-23-2012, 02:04 AM   #2
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
Is this what you want?

/etc/init.d/ssh status|grep -v "not running"|wc -l
 
Old 01-23-2012, 02:10 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
lets see what you have in the shell script..
 
Old 01-23-2012, 03:19 AM   #4
greenworld
LQ Newbie
 
Registered: Dec 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi,
Thank you for responses, the following output displayed.

[root@localhost ~]# /etc/init.d/ssh status|grep -v "not running"|wc -l
-bash: /etc/init.d/ssh: No such file or directory
0
[root@localhost ~]#

But i need ssh, smtp, ftp, pop status. it's running or stopped.

thank you,
 
Old 01-23-2012, 05:37 AM   #5
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
In my system /etc/init.d/ssh is the script that starts ssh, but it seems to be sshd in yours.

I thought you needed to get a 0/1 answer depending on the service running or not. Isn't that what you were looking for?

Last edited by rodrifra; 01-23-2012 at 05:39 AM.
 
Old 01-23-2012, 05:57 AM   #6
greenworld
LQ Newbie
 
Registered: Dec 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi,
Thank you for response, i m not clearly asking my queries? so sorry for that..

Now i was trying to below command find the POP3 server status,

# netstat -lnp | grep -v grep | grep '110 ' | grep 'LISTEN'

The output is : tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3017/sendmail: acce


This command checking POP3 status by Port number , Incase any one can change the port number how can i find out, the POP3 server LISTEN or NOT.
this same procedure i need SMTP, FTP, SSH.

I hopeful now you can understand.

Thank you,
 
Old 01-23-2012, 06:10 AM   #7
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
The port a service is listnening in is specified either in the configuration files or in /etc/xinit.d.
For instance, ssh has its configuration files in /etc/ssh. sshd_config is the file where the listening port is specified, so looking for the port there will give you the answer you are looking for whenever the service has been started with the standard configuration files. Otherwise, you will have to ps the ssh process, grep the specific config file that has been used to start it, and grep the port in that file. Then check that port with your query.

Last edited by rodrifra; 01-23-2012 at 06:15 AM.
 
1 members found this post helpful.
Old 01-23-2012, 06:16 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Or you have to assume sendmail is configured to listen on (some) port for POP3 and parse the output of /etc/init.d/ssh status to determine whether sendmail is running.
 
1 members found this post helpful.
Old 01-23-2012, 06:22 AM   #9
greenworld
LQ Newbie
 
Registered: Dec 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
ok,

Thank you for your response.

Bye.
 
Old 01-23-2012, 12:28 PM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
 
  


Reply

Tags
shell



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 commands in c++ _Chops_ Linux - General 3 09-27-2011 07:17 PM
[SOLVED] help with shell commands puth Programming 2 03-16-2010 01:24 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
commands in shell? kalleanka Linux - General 9 02-01-2006 07:38 AM
shell commands! krishlinux General 1 10-05-2003 04:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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

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