You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
2 years ago
|
#!/usr/bin/bash
|
||
|
|
||
|
DBfile=/home/jumpserver/.userdb
|
||
|
[[ ! -f $DBfile ]] && touch $DBfile
|
||
|
# vim /etc/rsyslog.conf local2.* /home/jumpserver/.login
|
||
|
LOGfile=/home/jumpserver/.login
|
||
|
LOGdev=local2
|
||
|
defRSA=/home/jumpserver/.ssh/id_rsa.pub
|
||
|
defPort=22
|
||
|
|
||
|
shaHash(){
|
||
|
echo -n "$1" |sha256sum |awk '{print $1}'
|
||
|
}
|
||
|
add_host(){
|
||
|
read -p "请输入新增ip地址:" nhost
|
||
|
read -p "请输入新增ip用途:" nfunc
|
||
|
read -p "请输入新增ip用户:" nuser
|
||
|
read -p "请输入新增ip描述:" ndesc
|
||
|
read -p "请输入新增ip密码:" npass
|
||
|
if [[ -z $nhost || -z $nfunc || -z $nuser || -z $npass ]];then
|
||
|
echo "输入信息无效"
|
||
|
sleep 1
|
||
|
return 1
|
||
|
fi
|
||
|
nseq=$[$(cat $DBfile |wc -l) + 1]
|
||
|
sha_pass=`shaHash $npass`
|
||
|
sshpass -p "$npass" ssh-copy-id -o StrictHostKeyChecking=no -i $defRSA -p $defPort ${nuser}@${nhost} &>/dev/null && \
|
||
|
echo "$nseq] $nhost $nuser $nfunc $sha_pass $ndesc" >> $DBfile && \
|
||
|
echo "服务器 $nfunc 已添加" && \
|
||
|
logger -p ${LOGdev}.info "$nseq $nuser $nhost $nfunc 服务器添加" || \
|
||
|
echo "添加服务器异常,请联系管理员"
|
||
|
sleep 2
|
||
|
}
|
||
|
|
||
|
login_host(){
|
||
|
printf "%-10s %-20s %-10s %-10s %-50s\n" "host" "ip" "user" "func" "desc"
|
||
|
while read line
|
||
|
do
|
||
|
printf "%-10s %-20s %-10s %-10s %-50s\n" `echo $line |awk '{print $1,$2,$3,$4,$6}'`
|
||
|
done <$DBfile
|
||
|
read -p "请输入服务器序号:" host
|
||
|
if [ ! -z $host ];then
|
||
|
host=${host:+$host]}
|
||
|
else
|
||
|
echo "输入序号无效"
|
||
|
return 2
|
||
|
fi
|
||
|
data=`grep "$host" $DBfile`
|
||
|
if [ -z "$data" ] ;then
|
||
|
echo "未找到服务器"
|
||
|
return 3
|
||
|
fi
|
||
|
fip=`echo $data | awk '{print $2}'`
|
||
|
fuser=`echo $data | awk '{print $3}'`
|
||
|
ssh $fuser@$fip
|
||
|
}
|