ipAllocate_and_linkState_hacking
#!/bin/bash
# Author: Joshua Chen
# Date: Jun
# Location: Shenzhen #. 解读这两个程序是因为程序中包含了大部分shell脚本的基本语法;
#. 省去以后需要使用到shell脚本的时候,需要参考的需求;
#. 在本代码中,以24位掩码为基准,如果IP为: 10.1.1.7,那么前面三位数是网络位: 10.1.,最后一位是主机位:
# -- 晴 深圳 曾剑锋 # Description: allocate IPs to students #每个人分配一个主IP, 3个辅助IP
EXTRA_COUNT=
#IP的前缀,相当这个脚本用于分配10..1段的IP,也就是网络位
IP_PREFIX=10.1.
#最多分配50个主IP
MAX_GRP=
#主IP的主机位从11开始
PRIM_MIN=
#主IP的主机位最大值
PRIM_MAX=$((PRIM_MIN + MAX_GRP -))
#扩展IP的主机位最小值
EXTRA_MIN=$((PRIM_MAX + ))
#扩展IP的主机位最大值
#EXTRA_MAX=$((EXTRA_MIN + MAX_GRP * EXTRA_COUNT -)) #获取传入的第一个参数,如果文件不存在,那个就退出,
#并且打印出命令的使用方法.
list=$
if [ ! -e "$list" ];then
#输出到标准错误输出
echo "Can not locate list file '$list'" >&
#需要传入有学生姓名的文件,每个学生名字占一行
echo "Usage: $(basename $0) <name list>"
exit
fi #检查list路径下文件的行数是否大于MAX_GRP,以下提供2种写法
#if [ $(wc -l "$list" | cut -d " " -f1) -gt "$MAX_GRP" ];then
if [ $(wc -l < "$list") -gt "$MAX_GRP" ];then
echo "Too many entries in the name list! maximum $MAX_GRP is allowed" >&
exit
fi #分配主IP
#每次从list代表的文件中读取一行名字,保存在name的变量中,
#然后是用printf组合分配IP.
echo "------- Primary IP -------"
n=$PRIM_MIN
while read name
do
printf "%s.%-3s %s\n" "${IP_PREFIX}" $n "$name"
((n++)) #语法要求,这样就可以像写C一样
done < "$list" #分配辅助IP
#因为辅助IP这里需要分配3个,所以while里面再是用for循环
#对IP进行分配.
echo
echo "------- Extra IP -------"
n=$EXTRA_MIN
while read name
do
for i in $(seq $EXTRA_COUNT) #seq用于产生序列供for循环使用
do
printf "%s.%-3s %s\n" "${IP_PREFIX}" $n "$name"
((n++))
done
done < "$list" #退出程序
exit # Description: detect the ethernet link state #网卡设备所在的目录
dir=/sys/class/net
#文件名carrier
file=carrier # need root privilege
if [ "$UID" -ne ]; then
echo "Must be root"
exit
fi if [ ! -d $dir ];then
echo "Directory $dir doesn't exist, quit."
exit
fi cd $dir # do we have an NIC? #Network Interface Card
if ! ls | grep -q ^eth; then
echo "No NIC detected"
exit
fi # check the status of each NIC
ls | grep ^eth | while read dev
do
# take it up first
ifconfig $dev up &> /dev/null # if the file is not found and put error to /dev/null
if [ "$(cat $dev/$file 2>/dev/null)" = "" ];then
echo "$dev: link ok"
else
echo "$dev: no link"
fi
done exit
ipAllocate_and_linkState_hacking的更多相关文章
随机推荐
- Excel表格的导入导出
Excel文件的组成: 01.一个Excel文件由N个Sheet组成的 02.一个Sheet由N个Row组成 03.一个Row由N个Cell组成 需求: 把内存中的数据 写入到指定的excel表格中! ...
- MongoDB(课时29 MapReduce)
3.7.4 MapReduce MapReduce 是整个大数据的精髓所在(实际中别用,因为在MongoDB中属于最底层操作). MapReduce是一种计算模型,简单的说就是将大批量的工作分解执行, ...
- C89_一些函数
C89 string.h 中的函数: 复制函数 memcpy memmove strcpy strncpy 串接函数 strcat strncat 比较函数 memcmp strcmp strcoll ...
- tp5.0 composer命令插件
1.单元测试composer require topthink/think-testing 1.* (5.0) composer require topthink/think-testing 5.1官 ...
- 工程优化暨babel升级小记
小记背景 随着业务代码的增多,项目代码的编译时长也在增多,遂针对这个痛点在dev下做些优化 第一部分:优化dev编译时间 这里优化的主要思路是在dev环境下,单独出来一个dll配置文件,将项目中的部分 ...
- 消息队列Kafka学习记录
Kafka其实只是众多消息队列中的一种,对于Kafka的具体释义我这里就不多说了,详见:http://baike.baidu.com/link?url=HWFYszYuMdP_lueFH5bmYnlm ...
- CF 711B - Chris and Magic Square
挺简单的一道题,但是做的时候没想好就开始写代码了,导致迷之WA,还是要多练习啊. #include <iostream> #include <cstdio> #include ...
- Lucky Array CodeForces - 121E (线段树,好题)
题目链接 题目大意: 定义只含数字$4,7$的数字为幸运数, 给定序列, 区间加正数, 区间询问多少个幸运数 题解: 对于每一个数, 求出它和第一个比它大的幸运数之差, 则问题转化为区间加,查询$0$ ...
- Skills CodeForces - 614D (贪心)
链接 大意: $n$门课, 第$i$门分数$a_i$, 可以增加共$m$分, 求$cnt_{mx}*cf+mi*cm$的最大值 $cnt_{mx}$为满分的科目数, $mi$为最低分, $cf$, $ ...
- thinkphp关于时间加减几天
1.当前时间,往后退5天: date('Y-m-d H:i:s',strtotime('-1 days')); 2.有固定时间,往后面退一天或者七天,或者30天: 比如时间:$time = 2014- ...