创建100个用户,密码dushan
#/bin/bash
for i in `seq 1 100`;
do
useradd user$i &>/dev/null
echo dushan | passwd --stdin user$i &>/dev/null
passwd -e user$i &>/dev/null
done
删除:for i in {1..100};do userdel -r user$i;done
后台扫描哪些ip是up哪些是down,up的存文件
#/bin/bash
> /data/iplist.log
net=172.20.129
for i in {1..254};do
{ if ping -c1 -w1 $net.$i &> /dev/null ;then
echo $net.$i is up
echo $net.$i >> /data/iplist.log
else
echo $net.$i is down
fi } &
done
wait
输入一个网段,扫描哪些是开机的
#/bin/bash
> /data/iplist.log
read -p "please input the network:(192.168.0.0): " net
net=echo $net|cut -d. -f1-3
for i in {1..254};do
{ if ping -c1 -w1 $net.$i &> /dev/null ;then
echo $net.$i is up
echo $net.$i >> /data/iplist.log
else
echo $net.$i is down
fi } &
done
wait
输入ip和netmask,得出idnet
#/bin/bash
read -p "input the ip: " ip
read -p "input the netmask: " netmask
for i in {1..4};do
net=`echo $ip |cut -d. -f$i`
mask=`echo $netmask |cut -d. -f$i`
if [ $i -eq 1 ];then
netid=$[net&mask]
else
netid=$netid.$[net&mask]
fi
done
echo netid=$netid
优化
#/bin/bash
read -p "input the ip: " ip
read -p "input the netmask: " netmask
for i in {1..4};do
net=`echo $ip |cut -d. -f$i`
mask=`echo $netmask |cut -d. -f$i`
subnetid=$[net&mask]
if [ $i -eq 1 ];then
netid=$subnetid
else
netid=$netid.$subnetid
fi
done
echo netid=$netid