前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux Bash脚本练习3

Linux Bash脚本练习3

作者头像
py3study
发布2020-01-14 10:11:18
2.5K0
发布2020-01-14 10:11:18
举报
文章被收录于专栏:python3python3

1.任务描述:

写一个脚本实现如下功能:

manageuser.sh --add user1,user2,user3,...

manageuser.sh --del user1,user2,user3,...

manageuser.sh --help

要求,如果用户不存在,才能添加,并用户密码同用户名;如果delete存在用户,那么用户的家目录一同delete掉;提供--help进行用户提示。

#!/bin/bash # if [ $# -lt 1 ] ; then    echo "no args"    exit 7 fi if [ $1 == "--add" ] ; then        if [ $# -gt 2  ] ; then       echo "no userlist"       exit 8      fi    for i in `echo $2 | sed 's/,/ /gi'` ; do         if id $i &>/dev/null ; then             echo "$i is exits"         else             useradd $i             echo $i | passwd --stdin $i &> /dev/null             echo "$i is added..."         fi    done   fi if [ $1 == "--del" ] ; then        if [ $# -gt 2 ] ; then       echo "no userlist"       exit 8      fi    for i in `echo $2 | sed 's/,/ /gi'` ; do         if id $i &>/dev/null ; then            userdel -r $i            echo "delete $i"         else             echo "$i is not found"         fi    done   fi if [ $1 == "--help" ] ; then    echo -e "manageuser.sh --help\nmanageuser.sh --add user1,user2...\nmanageuser.sh --del user1,usesr2..." fi

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档