批量添加或删除用户

==========================================================================================

#!/bin/bash

#

if [ ! $# -eq 1 ];then

echo ‘./user.sh --add|--del‘

exit 1

fi

case "$1" in

--add)

for i in {1..10}

do

if id user$i &>/dev/null ;then

echo "user$i is exists."

else

useradd user$i

echo "user$i" |passwd --stdin user$i &> /dev/null

echo "Add user user$i finished."

fi

done

;;

--del)

for i in {1..10}

do

if id user$i &>/dev/null ;then

echo "Delete user$i  finished."

userdel -r user$i

else

echo "user$i is not found."

fi

done

;;

*)

echo ‘./user.sh --add|--del‘

esac

==========================================================================================

#!/bin/bash

if [ $# -lt 2 ];then

echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"

exit 1

fi

if [ $1 == "--add" ];then

for I in `echo $2|sed ‘s/,/ /g‘`

do

if id $I &> /dev/null;then

echo "$I exists."

exit 9

else

useradd $I

echo $I |passwd --stdin $I &>/dev/null

echo "Add user $I finished."

fi

done

elif [ $1 == "--del" ];then

for I in `echo $2|sed ‘s/,/ /g‘`

do

if id $I &> /dev/null;then

userdel -r $I

echo "Delete user $I finished."

else

echo "No sush $I. "

exit 9

fi

done

elif [ $1 == "--help" ];then

echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"

else

echo "Usage $0 --add user1,user2,user3|--del user1,user2,user3|--help"

fi

批量添加或删除用户

时间: 2024-08-25 00:11:03

批量添加或删除用户的相关文章

Ansible 从MySQL数据库添加或删除用户

mysql_user - 从MySQL数据库添加或删除用户. 概要 要求(在执行模块的主机上) 选项 例子 笔记 状态 支持 概要 从MySQL数据库添加或删除用户. 要求(在执行模块的主机上) MySQLdb的 选项 参数 需要 默认 选择 注释 append_privs (1.4 加入) no no yes no 将priv定义的权限附加到此用户的现有权限,而不是覆盖现有的权限. check_implicit_admin (1.3 加入) no no yes yes 检查mysql是否允许以

123批量添加和删除单元格(扩展知识:设置单元格的尺寸和颜色)

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UITableViewController 4 @property (strong, nonatomic) NSMutableArray *mArrDataSource; 5 6 @end ViewController.m 1 #import "ViewController.h" 2 3 @interface Vi

Windows批量添加和删除IP

随着天气变冷了,好多小伙伴都开始变懒了,都想用最快的方式完成任务 下面给大家介绍一下Windows批量添加和删除IP的办法 (1)批量添加IP 直接在CMD下边运行下边命令. for /l %i in (2,1,254) do netsh interface ip add address "本地连接" 192.168.1.%i 255.255.255.0for /l %i in (2,1,62) do netsh interface ip add address "本地连接&

rhel7 批量新建和删除用户

若需要批量新建或者删除用户,可使用简单脚本操作. 首先新建 users.txt,将要新建或者删除的用户放进去, 1 andy 2 barry 3 carl 4 duke 5 eric 6 george 7 kim 8 mary 然后编写Example.sh,(新建用户) 1 then 2 echo "Already exists" 3 else 4 useradd $UNAME &> /dev/null 5 echo "$PASSWD" | passw

Linux系统编写shell脚本批量创建和删除用户

一.编写shell脚本批量添加用户 实现方法:判断用户是否存在,存在则返回错误提示,同时判断用户文件是否存在,不存在则退出 1.创建添加用户脚本 [[email protected] ~]# vim useradd.sh #!/bin/bashif [ $# -eq 0 ];then        echo "你没有输入任何文件!"        exit 1fi if [ ! -f $1 ];then        echo "输入有误!"        exit

linux批量添加10个用户并将其随机密码和用户名写入文件

需求: 批量新建10个测试用户,并且让其密码随机,把用户名和密码写入一个文件,并有创建时间和创建者 #!/usr/bin/python # -*- coding: utf-8 -*- import os import random import time import io def deluser(nums): '''删除用户测试用户''' for i in range(nums): username = 'stu' + str(i) linux_cmd = 'userdel -r {usern

centos添加和删除用户及 xxx is not in the sudoers file.This incident will be reported.的解决方法

1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户 #passwd tommy   //修改密码 Changing password for user tommy. New UNIX password:     //在这里输入新密码 Retype new UNIX password:  //再次输入新密码 passwd: all authentication tokens updated successfully.

Shell 脚本添加或删除用户及命令使用方法

Shell 要求:写一个脚本 一.添加10个用户user1到user10,密码同用户名,,若用户存在,但要求只有用户不存在的情况下才能添加,格式为/useradd.sh 解答思路:1.使用for 循环语句添加用户 user1 到user 10 2.判断用户是否存在,若存在,则echo 用户已存在 ,若不存在,添加用户 ,并设置密码与用户名相同 . 脚本: vim useradd.sh  并赋予+x权限. #!/bin/bash # for I in{1..10};do      if id us

mysql、添加和删除用户、添加权限

创建用户 mysql>insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); 添加了一个username为test.password为1234用户.但该用户仅仅能在本地登陆,若想远程登陆的话可将localhost改为%表示不论什么一台电脑都能够登陆.或改为特定的ip表示仅仅能在特定的ip地址上登陆. 为用户加入权限 mys