首页 > 系统服务 > 详细

老李分享:《Linux Shell脚本攻略》 要点(六)

时间:2015-11-23 18:27:15      阅读:289      评论:0      收藏:0      [点我收藏+]
1、打印网络接口列表
[root@localhost touch_more]# ifconfig | cut -c-10 | tr -d ‘ ‘ | tr -s ‘\n‘
eth0
lo
//cut -c-10 ;  输出前10个字符;
//tr -d ‘ ‘ ;      删除所有空格;
//tr -s ‘\n‘;     压缩重复的换行符
 
2、查看名字服务器
[root@localhost touch_more]# cat /etc/resolv.conf 
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.119.2
 
3、DNS查找
[root@localhost touch_more]# nslookup www.csdn.net
Server:         192.168.119.2
Address:        192.168.119.2#53

Non-authoritative answer:
www.csdn.net    canonical name = www.csdn.net.aqb.so.
Name:   www.csdn.net.aqb.so
Address: 14.17.69.22
 
4、列举出局域网中同一网段的所有的活动主机

[root@localhost program_test]# cat list_active_hosts.sh 
#!/bin/bash

for ip in 192.168.119.{1..255} ;
do
ping $ip -c 2 &> /dev/null;

if [ $? -eq 0 ];
then
echo $ip is active!
fi
done
[root@localhost program_test]# ./list_active_hosts.sh 
192.168.119.1 is active!
192.168.119.2 is active!

5、系统运行时间监视

<pre name="code" class="plain" style="font-size: 14px;">[root@localhost program_test]# cat ssh_test.sh
#!/bin/bash

IP_LIST="192.168.119.1 192.168.119.2 192.168.119.128"
USER="yxy"

for ip in $IP_LIST;
do
utime=$(ssh $USER@$ip uptime | awk ‘{ print $3 }‘ )
echo $ip uptime: $utime
done

 

老李分享:《Linux Shell脚本攻略》 要点(六)

原文:http://www.cnblogs.com/poptest/p/4988968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!