Shell脚本:判断用户和用户组是否已经存在/创建用户和用户组
来源:互联网 发布:dorado js 编辑:程序博客网 时间:2024/06/05 23:47
通常作为一个应用程序的部署脚本,开始的第一项工作是为当前应用创建一个专用(dedicated)的用户和用户组。这个脚本很简单,这里贴一个参考样本:
#!/bin/shuser=test_usergroup=test_group#create group if not existsegrep "^$group" /etc/group >& /dev/nullif [ $? -ne 0 ]then groupadd $groupfi#create user if not existsegrep "^$user" /etc/passwd >& /dev/nullif [ $? -ne 0 ]then useradd -g $group $userfi
对于添加用户来说,我们还可以使用id命令来判断一个用户是否存在,这样建立一个用户的脚本可以这样写:
#create user if not existsid $user >& /dev/nullif [ $? -ne 0 ]then useradd -g $group $userfi
但是,使用id命令不能判断一个用户组是否已经存在!至于使用id -g $user只能给出一个已存在的用户所属的用户组是什么,并不能判断一个用户组是否已经存在,所以,为了使用脚本的处理方式统一,我们统一使用从/etc/group和/etc/passwd文件中进行查找的方式来判断一个用户组和用户是否存在!
2 1
- Shell脚本:判断用户和用户组是否已经存在/创建用户和用户组
- 如何创建用户组和用户
- linux 创建用户和用户组
- linux用户和用户组
- Linux 用户和用户组
- 用户和用户组
- 用户和用户组
- linux用户和用户组
- Linux 用户和用户组
- Linux---用户和用户组
- 用户和用户组管理
- 用户和用户组文件
- Linux用户和用户组
- linux用户和用户组
- Linux用户和用户组
- Linux用户和用户组
- Linux用户和用户组
- 用户,用户组和权限
- [Intel汇编-MASM]外中断
- jax-ws之webservice security(安全)教程第二天
- 维吉尼亚加密
- jax-ws之webservice security(安全)教程第三天
- Linux 内核
- Shell脚本:判断用户和用户组是否已经存在/创建用户和用户组
- opencv学习笔记之六 颜色空间的转换
- Eclipse中打开windows资源管理器或打开文件夹的设置!(实例)
- vertical-align
- OpenCV学习: 轮廓的特征矩Moment
- 一个小程序笔记-java中浮点型细节
- 通过id和class删除html元素
- CorePlots 不支持64位解决方案 以及 CorePlots 相关
- 【第一次作业】