#!/usr/bin/bash
###############################################
# yum config #
# by kuibaobao #
###############################################
#获取版本号cat /etc/redhat-release
os_vsrsion=`cat /etc/redhat-release | awk '{print $4}' | awk -F"." '{print $1"."$2}'`
[ -d /etc/yum.repos.d ] || mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/{*.repos,bak}
if [ "$os_version"="7.3"]; then
elif [ "$os_version"="6.8"]; then
elif [ "$os_version"="6.3"]; then
else
echo "No version"
fi
ss -tnlp | grep vsftpd //vsftpd 地址 端口 pid
netstat -tnlp | grep vsftpd
for 空行的秘密
IFS $’\n’ //循环次数的分割方式
#!/usr/bin/bash
#ping check
> ip.txt
for i in {2..254}
do
ip=125.124.15.$i
ping -c1 $ip &>/dev/null
if [ $? -eq 0 ]; then
echo "$ip" | tee -a ip.txt
fi
done
#wait #等待所有的后台程序进行完毕
echo "finishi...."
从文件中获取ip
#!/urs/bin/bash
for ip in `cat ip.txt`
do
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo "$ip is up "
fi
done
实现批量用户创建
#!/usr/bin/bash
#######################
# useradd #
#v2.0 by kuibaobao #
#######################
while :
do
read -p "please enter prefix & passwd & num :" prefix passwd number
printf "user infomation
----------------------------------------
user prefix : $prefix
user passwd : $passwd
user number : $number
----------------------------------------
"
read -p "Are you sure?[y/n]:" action
if [ "$action" = "y" ]; then
break
fi
done
for i in `seq -w $number`
do
user=$prefix$i
id $user &>/dev/null
if [ $? -eq 0 ]; then
echo "user $user already exists"
else
useradd $user
echo "$passwd" | passwd --stdin $user &>/dev/null
if [ $? -eq 0 ]; then
echo "$user is created."
fi
fi
done
文件中批量用户的创建
#!/usr/bin/bash
if [ $# -eq 0 ]; then
echo "usage:`basename $0` file"
exit 1
fi
if [ ! -f $1 ]; then
echo "error file"
exit 2
fi
#IFS=$'\n'
IFS='
'
for line in `cat $1`
do
if [ ${#line} -eq 0 ]; then
continue
fi
user=`echo "$line"|awk '{print $1}'`
pass=`echo "$line"|awk '{print $2}'`
id $user &>/dev/null
if [ $? -eq 0 ];then
echo "user $user already exists"
else
useradd $user
echo "$pass" | passwd --stdin $user &>/dev/null
if [ $? -eq 0 ]; then
echo "$user is created."
fi
fi
done
批量远程主机的ssh配置
简易版
#!/usr/bin/bash
#v1.0 by kuibaobao
for ip in `cat ip.txt`
do
{
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ]; then
ssh $ip "sed -ri '/^#UseDNS/cUseDNS no' /etc/ssh/ssh_config"
fi
}&
done
wait
echo "all ok..."
while until循环
while循环创建用户
#!/usr/bin/bash
# while-useradd
#v1.0 by kuibaobao
while read line
do
if [ ${#line} -eq 0 }; then
continue
fi
user=`echo "$line"|awk '{print $1}'`
pass=`echo "$line"|awk '{print $2}'`
id $user &>/dev/null
if [ $? -eq 0 ]; then
echo "$user already exists"
else
useradd $user
echo "$pass"|passwd --stdin $user &>/dev/null
if [ $? -eq 0 ]; then
echo "$user is created."
fi
fi
done < user.txt