#####用户建立###
要求:给定两个文件一个存放用户名,一个存放密码,建立用户,并做出两个文件行数不同,用户存在,以及文件不存在的情况
------------------------------------------------------------------------------------------------------------
#!/bin/bash
[ "$#" != 2 ] &&echo ERROR:Please input like this:$0 username password&&exit 1
[ ! -f "$1" ] &&echo ERROR:$1 is not a file&&exit 2
[ ! -f "$2" ] &&echo ERROR:$2 is not a file&&exit 3
user=$(cat $1 |wc -l )
pass=$(cat $2 |wc -l )
[ "$user" != "$pass" ]&&echo ERROR:The two files line number is different&&exit 4
for ((i=1;i<=$user;i++))
do
username=$(sed -n ${i}p $1)
id $username &>/dev/null
if [ "$?" == 1 ];then
useradd $username
echo $(sed -n ${i}p $2)|passwd $username --stdin &>/dev/null
echo $username:user set up successful!
else
echo $username:User already exists!Skip this user!
fi
done
-------------------------------------------------------------------------------------------------------------
#####ssh远程登录####
要求:在脚本后面输入用户名,密码,ip即可链接并登录
---------------------------------------------------------------------------------------------