Article Title: Port-based service check script in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
#! /Bin/bash
# Program: Usingtostudythe [if... then... fi] program
# Dsk2007/10/83: 00
# Content: Iwillusingthisprogramtoshowyousevices
#1. printtheprogram ''sworkinyourscreen
Echo "Now, the service of your Linux system will be detect! "
Echo "The www, ftp, ssh, and sendmail pop3 will be detect! "
Echo ""
# 2.www
Www = 'netstat-ntlp | awk' {print $4} '| grep: 80 $'
If ["$ www "! = ""];
Then
Echo $ www
Echo "WWW is runing"
Else
Echo $ www
Echo "WWW is NOT runing"
Killall-9 httpd
/Usr/sbin/apachectl start
# Service httpd start
Fi
# 3.ftp
Ftp = 'netstat-an | grep LISTEN | grep: 21'
If ["$ ftp "! = ""]; Then
Echo $ ftp
Echo "FTP is runing"
Else
Echo "FTP is not runing"
Killall-9 vsftpd
# Service vsftpd start
/Etc/init. d/vsftpd start
Fi
# 4.ssh
Ssh = 'netstat-ntlp | awk' {print $4} '| grep: 22 $'
# Ssh = 'netstat-an | grep LISTEN | grep: 22'
If ["$ ssh "! = ""]; Then
Echo $ ssh
Echo "SSH is running"
Else
Echo "SSH is not running"
Fi
#5. sendmail pop3
Smtp = 'netstat-an | grep LISTEN | grep: 25'
Pop3 = 'netstat-an | grep LISTEN | grep: 8080'
If ["$ smtp "! = ""] & ["$ Pop3 "! = ""]; Then
Echo "Send mail is OK! "
Elif ["$ smtp "! = ""] & ["$ Pop3" = ""]; then
Echo "Send mail have some problems of your pop3! "
Elif ["$ smtp" = ""] & ["$ pop3 "! = ""]; Then
Echo "Send mail have so me problems of your smtp! "
Else
Echo "Send mail is NO Trunning! "
Fi