LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Need some SHELL commands (http://www.linuxquestions.org/questions/linux-server-73/need-some-shell-commands-925200/)

greenworld 01-23-2012 01:46 AM

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,

rodrifra 01-23-2012 02:04 AM

Is this what you want?

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

cbtshare 01-23-2012 02:10 AM

lets see what you have in the shell script..

greenworld 01-23-2012 03:19 AM

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,

rodrifra 01-23-2012 05: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 05:57 AM

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,

rodrifra 01-23-2012 06: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 06: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 06:22 AM

ok,

Thank you for your response.

Bye.

David the H. 01-23-2012 12: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 10:29 PM.