实验三
① 显示输入恢复的目录,若目录不存在,提示:目录不存在,恢复失败;若存在,提示:请输入要恢复的文件
② 判断该文件是否存在,若存在,判断该文件是否为空,若不为空,则解包解压缩;若空,则将当前日期重定向到该文件中;判断该文件是否可写可执行,若不是,则将其权限改为可写可执行;若是,则提示可写可执行。否则提示文件不存在,恢复失败。
③ 循环,创建50个用户,用户名用user1到user50,若用户已经存在,则先删除再创建。
echo “Please input the directory :”
read dir
if test -d $dir
then
cd $dir
echo “Please input the file you look for :”
read file
if test -s $file #f文件存在并且不为空
then
gunzip $file.gz
tar xvf $file
echo “recovery successfully !”
else
date>$file
if [ -r $file -a -w $file ] #判断文件是否可读可写,-a是与的作用
then
echo “$file can read and write !”
else
chmon u=rw, g=rw $file
fi
fi
else
echo “directory is not exists !”
fi
for((i=1;i<=50;i++))
do
if grep $user$i /etc/passwd
then
userdel -r user$i
else
useradd -u user$i
fi
done