Port-based service check script in Linux

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.