编写一个shell要求如下:
定义变量X,Y,Z
创建用户user1,user2,user3
当执行此shell后将提示:
Please enter the letters:
输入X时将自动在user1用户下创建一个/aix目录并且创建10个文件
当输入Y时将自动切换user2并查看/tmp下的文件
当输入Z时将切换至user3 且在5秒后自动切回root用户后并中断shell
#!/bin/bash
#guying
useradd user1 1>/dev/null 2>/dev/null
useradd user2 1>/dev/null 2>/dev/null
useradd user3 1>/dev/null 2>/dev/null
stty erase "^H3"
read -p "Please enter the letters:" mx
if [ $mx == "X" ];then
su - user1 -c "` mkdir /home/user1/aix 1>/dev/null 2>/dev/null
for i in {1..10}
do
touch /home/user1/uu$i
done`"
elif [ $mx == "Y" ];then
su - user2 -c "ls /tmp"
elif [ $mx == "Z" ];then
su - user3 -c "`count=1;
while true;
do
if [ $count -lt 5 ];then
let count++;
sleep 1;
else
exit
fi
done`"
else
echo "Please X|Y|Z"
fi
阅读(1567) | 评论(0) | 转发(0) |