实验三

来源:互联网 发布:cad图纸查看软件 编辑:程序博客网 时间:2024/04/29 19:38

实验三

     显示输入恢复的目录,若目录不存在,提示:目录不存在,恢复失败;若存在,提示:请输入要恢复的文件

     判断该文件是否存在,若存在,判断该文件是否为空,若不为空,则解包解压缩;若空,则将当前日期重定向到该文件中;判断该文件是否可写可执行,若不是,则将其权限改为可写可执行;若是,则提示可写可执行。否则提示文件不存在,恢复失败。

     循环,创建50个用户,用户名用user1user50,若用户已经存在,则先删除再创建。

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