1、shell 脚本写出检测 /tmp/size.log 文件如果存在显示它的内容,不存在则创建一个文件将创建时间写入。
#! /bin/bash
filePath="/tmp/size.log"
if [ -e $filePath ]
then
awk '{print $0}' $filePath
else
echo $(date +"%Y-%m-%d %T") > $filePath
fi
2、写一个 shel1 脚本,实现批量添加 20个用户,用户名为user01-20,密码为user 后面跟5个随机字符。
#!/bin/bash
for i in user{01..20}
do
if ! id $i &> /dev/null
then
passWord=$i$(openssl rand -base64 4 | cut -c 1-5)
echo $passWord >> ./passWord.bak.txt
useradd $i && echo $passWord | passwd --stdin $i
else
echo "$i does exist!"
fi
done
3、编写个shel 脚本将/usr/local 日录下大于10M的文件转移到/tmp目录下
#!/bin/bash
filePath='/usr/local/'
for i in $filePath*
do
Size=$(du -d 0 --bytes $i | awk '{print $1}')
if (($Size >= 10485760))
then
mv $i /tmp/
result=$(echo "scale=2; $Size / 1048576" | bc)
printf "$i : %.2f M\n" $result
fi
done