-   Linux - Server (
-   -   Need some SHELL commands (

greenworld 01-23-2012 02:46 AM

Need some SHELL commands

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

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,

rodrifra 01-23-2012 03:04 AM

Is this what you want?

/etc/init.d/ssh status|grep -v "not running"|wc -l

cbtshare 01-23-2012 03:10 AM

lets see what you have in the shell script..

greenworld 01-23-2012 04:19 AM

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
[root@localhost ~]#

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

thank you,

rodrifra 01-23-2012 06:37 AM

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?

greenworld 01-23-2012 06:57 AM

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* 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,

rodrifra 01-23-2012 07:10 AM

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.

catkin 01-23-2012 07:16 AM

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.

greenworld 01-23-2012 07:22 AM


Thank you for your response.


David the H. 01-23-2012 01:28 PM

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.

All times are GMT -5. The time now is 08:23 PM.