Shell Example
Requirement 1: follow the file to add user and set password
File name: user_passwd
File content:
aaa 123456
bbb 123456
ccc 123456
Program 1: 1.sh
#!/bin/bash
for I in `cut -d' ' -f1 $1`
do
useradd $I
P=$(grep $I $1 | cut -d' ' -f2)
echo $P | passwd $I --stdin
done
Execute: ./1.sh user_passwd
Program 2: 2.sh
#!/bin/bash
cat $1|while read username password
do
useradd $username
echo $password|passwd --stdin $username
done
Execute: ./2.sh user_passwd
Requirement 2: follow the file to delete user
File name: user_passwd
File content:
aaa 123456
bbb 123456
ccc 123456
Program: 3.sh
#!/bin/bash
for I in `cut -d' ' -f1 $1`
do
userdel -r $I && echo "delete user $I"
done
Execute: ./3.sh user_passwd
Comments
Post a Comment