# !/bin/bash # program: Using to study the [if ... then ... fi] program # Written by Edward # Date:2012/08/06 # content:I will using this program to show your services # 1. print the program's work in your screen. echo "Now,the services of your Linux system will be detect!" echo "The ww,ftp,ssh,and sendmail + pop3 will de detected!" echo " " # 2. www www='netstat -an|grep LISTEN|grep :80' if [ "$www" != "" ];then echo "WWW is running." else echo "WWW is NOT running." fi # 3.ftp ftp='netstat -an|grep LISTEN|grep :21' if [ "$ftp" != "" ];then echo "FTP is running." else echo "FTP is NOT running." fi # 4.ssh ssh='netstat -an|grep LISTEN|grep :22' if [ "$ssh" != "" ];then 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 :110' if [ "$smtp" != "" ] && [ "$pop3" != "" ];then echo "sendmail is OK!" elif [ "$smtp" != "" ] && [ "$pop3" = "" ];then echo "sendmail have problem of your pop3." elif [ "$smtp" = "" ] && [ "$pop3" != "" ];then echo "sendmail have some problem of your smtp." else echo "sendmail is NOT running." fi
在本人电脑上运行的结果:
几点体会:
1. 仅仅用命令就可以检测主机的网络端口情况,挺轻松的。
2. 复习了一下网络命令‘netstat -an',用于检查网络状态。
3. shell编程虽然可以说是一种脚本式语言,但是在学习过C和C++以后,脚本式语言学习起来确实会轻松不少。
4. 对操作系统知识的掌握有助于理解shell编程的内涵。
5. shell终端下的命令其实是提供给用户以使用系统服务的接口。
非原创,来自《鸟哥的linux私房菜》第12章《学习使用shell scripts》
原文链接: https://www.cnblogs.com/edward1992/archive/2012/08/06/2624523.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/58282
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!