#!/bin/bash
if [ ! -d /usr/test00 ]; then
sudo mkdir /usr/test00
fi
cd /usr/test00
for i in {1..20}
do
dir_name=''
if [ $i -lt 10 ]; then
dir_name=stu0${i}
else
dir_name=stu${i}
fi
#判断目录是否存在
if [ -d $dir_name ]; then
continue
fi
sudo mkdir ${dir_name}
done
#!/bin/bash
username=stu01
#创建用户stu01,其密码为123456,并且拥有自己的文件夹,文件夹名为/home/stu01
useradd -d /home/${username} -m -s /bin/bash -p $(echo 123456 | openssl passwd -1 -stdin) ${username}
#允许stu01用户远程登录
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
#配置用户最短使用期限10天,最长使用期限为90天
chage -m 10 -M 90 ${username}
#提取出账号过期时间
overdue=$(chage -l ${username} | grep '密码过期时间' | awk '{print $3,$4,$5}')
echo 账号${username}密码过期时间为"${overdue}"#!/bin/bash
#获取当前服务器的IP地址
IP=`/sbin/ifconfig -a|grep inet|grep -v inet6|grep -v 127.0.0.1|awk '{print $2}'|tr -d "addr:"`
#以.分割IP地址
IP_ARR=(${IP//./ })
#获取网段
NETWORK=${IP_ARR[0]}.${IP_ARR[1]}.${IP_ARR[2]}.
num=0
for i in {125..130}
do
#检查是否存在该IP地址
ping -c 1 -w 1 ${NETWORK}$i &>/dev/null
if [ $? -eq 0 ];then
echo 找到了${NETWORK}${i}
num=`expr ${num} + 1`
fi
done
echo Ping通了${num}台服务器#!/bin/bash
#获取历史操作,并按行保存到文件中
#情空两个日志文件,不存在就创建
:> command.log
:> command_01.log
cat ~/.bash_history|while read line
do
echo ${line}>>command.log
done
cat command.log|while read line
do
#如果这一行有sudo
if [[ $line != *"sudo"* ]]
then
#获取这一行的第一个参数
echo \#${line}>>command_01.log
else
echo ${line}>>command_01.log
fi
done#!/bin/bash
source_url=""
#获取传入的参数
case $1 in
"1")
#清华源
source_url="https:\/\/mirror.tuna.tsinghua.edu.cn\/"
;;
"2")
#浙大源
source_url="http:\/\/mirrors.zju.edu.cn\/"
;;
"3")
#中科大源
source_url="https:\/\/mirrors.ustc.edu.cn\/"
;;
*)
echo "参数错误"
exit 1
;;
esac
#换源
sudo sed -i -r "s/(http|https):\/\/[a-z.]+\//${source_url}/" /etc/apt/sources.list
#更新缓存
sudo apt-get clean
#更新源
sudo apt-get update