1.建立脚本要求

1)编写script.sh,使用方式:script.sh /mnt/userfile /mnt/passfile

2)当要求建立用户已经存在不作任何操作

3)当脚本后所指定文件个数少于2个,please give me userfile or passfile

4)当所给文件的行数不一致,/mnt/userfile's lines is different with /mnt/passfile's lines


2.script.sh

建立用户脚本


建立用户脚本


[ "$#" -lt "2" ]                                ##验证脚本后所指定的文件是否小于两个


N = `cat $1 | wc -l `                    ##查看$1(即脚本后所指定的第一个文件)行数,M同


[ "$N" -ne "$M" ]                         ##若第一个文件与第二个文件行数不相等


[ "id `cat $1`;echo $?" ="0" ]    ##检测用户是否已创建过


for ((i=1;i<=$N;i++))                 ##for循环,当i小于$N(即userfile的行数时),i++,以便连续创建用户


sed -n ${i}p $1                         ##单独列出$1(userfile)文件中的第一行,后经过for循环逐步列出每一行


3.测试

建立用户脚本


创建userfile 中的用户,以passfile中的数据为密码

建立用户脚本


脚本后所指定文件数少于两个

建立用户脚本


删除passfile最后一行密码,userfile与passfile文件行数不等

建立用户脚本


当所创建用户已存在时,不作任何操作

建立用户脚本

相关文章:

  • 2021-06-29
  • 2021-12-17
  • 2022-03-05
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-05-21
猜你喜欢
  • 2021-12-20
  • 2021-07-06
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-09-15
相关资源
相似解决方案