1.IPMI工作原理图:

2.脚本实现流程图:

3.适配服务器机型:

4.演示效果:

5.实现代码:

 #!/usr/bin/env bash

 # Author      : JACK ZHAO
# Date : //
# Description : This script is userd to manage the PC server remote management card account. ###Global variable###
WORKDIR=`pwd`
SSH_PORT=
IPMI_PORT=
instool=${WORKDIR}/instool3.-pre/instool.sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export LC_ALL=C /bin/stty erase ^H
[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
[ ! -d ${WORKDIR}/temp ] && mkdir ${WORKDIR}/temp ###Common function###
colour (){
case $ in
default)
echo -ne "\033[0m"
;;
default_red)
echo -ne "\033[31m"
;;
esac
} aciton_false(){
action "$1" /bin/false
} action_true(){
action "$1" /bin/true
} ###Defining countdown###
readsecond(){
for i in `seq -w - `;do
echo -ne "\b\b\b\b\b\b\b\b\b\b\b\b\bCountdown:\033[1;34m${i}\033[0ms"
sleep
done
} ###Check the IP format###
check_ip_format(){
ipcalc -cs $
if [ $? -eq ];then
return
else
return $RC
fi
} ###Check whether IP is online###
check_ip_alive(){
ping -c -w $ &>/dev/null
if [ $? -eq ];then
return
else
return $RC
fi
} ###Check Port###
check_port(){
nc -vuz $ $ &>/dev/null
if [ $? -eq ];then
return
else
return
fi
} ###Summary of inspection conditions###
chenck_ip_port(){
check_ip_format $
if [ $? -ne ];then
aciton_false "$1 Invalid IP."
return
fi
check_ip_alive $
if [ $? -ne ];then
aciton_false "$1 Network connection failed."
return
fi
check_port $IP $IPMI_PORT
if [ $? -ne ];then
aciton_false "$1 UDP 623 Port connection failed."
return
fi
return
} ###Public function ###
enter_account_ip(){
while true;do
read -p "Input Your IP:" IP
chenck_ip_port ${IP}
[ $? -ne ] && enter_account_ip
read -p "Input Your Administrator:" USERNAME
read -s -p "Input Your Password:" PASSWORD
echo ""
read -p "Are You Sure?(y/n):" ANSWER
if [ -z $USERNAME ] && [ -z ${PASSWORD} ];then
colour default_red
echo "Username and password cannot be empty."
colour default
continue
fi
case ${ANSWER} in
y|Y|yes|YES) break;;
*) ;;
esac
done
} ###Check the DELL IPMI state###
check_dell_ipmi(){
DELL_IPMI_STATUS=`sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet ${}@$ racadm get iDRAC.IPMILan.Enable | tail -n1 | awk -F "=" '{print$2}'`
if [ "$DELL_IPMI_STATUS" == "Disabled" ];then
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet ${}@$ racadm set iDRAC.IPMILan.Enable Enabled
if [ $? -ne ];then
aciton_false "$1 Open the IPMI server failure."
exit
fi
fi
} ###User list###
query_user_list(){
echo "-----------------------User List---------------------------"
ipmitool -I lanplus -U ${USERNAME} -P ${PASSWORD} -H ${IP} user list
if [ $? -ne ];then
colour default_red
echo "ERROR: Incorrect username or password,Please try again!"
colour default
fi
return
} ###Use help###
useage(){
cat << EOF
+------------------------------------------------------------------------------+
|Notice:Please save the server IP address to the file in the following format. |
|For example: |
|--------------+--------------+--------------+---------------+-----------------|
|Create user:              |
|IP Login_username Login_password new_username new_password |
|192.168.70.125 root calvin userid hdli2016 |
|...           |
|Update user:           |
|IP Login_username Login_password update_username new_password |
|192.168.70.125 root calvin userid hdli2016 |
|...           |
|Delete user:              |
|IP Login_username Login_password delete_username |
|192.168.70.125 root calvin userid      |
|...             |
|Disable user:              |
|IP Login_username Login_password Disable_username |
|192.168.70.125 root calvin userid      |
|... |
|--------------+--------------+--------------+---------------+-----------------|
|NAME |
| PC_RAC_ACCOUNTS_MGT_TOOL.sh version 1.0. |
|Detailed |
| http://www.cnblogs.com/changmingzhao/p/7826333.html |
+------------------------------------------------------------------------------+
EOF
readsecond
} ###Check whether the user exists###
check_user_exist(){
ipmitool -I lanplus -U $ -P $ -H $ user list | grep -wv "ID" | awk '{print$1"\t"$2}' | egrep -v "true|false" > ${WORKDIR}/temp/user_info.temp > /dev/null
if `grep -wq "$4" ${WORKDIR}/temp/user_info.temp`;then
return
else
return
fi
} ###Check the username and password###
check_login_username_passwd(){
ipmitool -I lanplus -U $ -P $ -H $ user list &> /dev/null
if [ $? -eq ];then
return
else
return
fi
} ###2.3 Adding HP server ILO users###
add_user_hp(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -eq ];then
aciton_false "$1 User:$4 Already Exist."
else
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ create /map1/accounts1 username=$ password=$ name=$ group=admin,config,oemhp_vm,oemhp_rc,oemhp_power &> /dev/null
if [ $? -eq ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -aw "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###2.2 Adding Inspur server BMC users###
add_user_inspur(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -eq ];then
aciton_false "$1 User:$4 Already Exist."
else
${instool} $ $ $ -lan -user -list | awk '{print$1}' | grep -v "ID" > ${WORKDIR}/temp/user_id_inspur.temp > /dev/null
for ((i=;i++;i<=));do
grep -qw $i ${WORKDIR}/temp/user_id_inspur.temp && continue
${instool} $ $ $ -lan -user -addm $i $ $ admin &> /dev/null
break
done
${instool} $ $ $ -lan -user -list &>/dev/null
if [ $? -eq ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep "Product Serial" | awk -F ":" '{print$2}'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###2.1/2.4/2.5 Adding Lenovo, Huawei, DELL server to remote management users###
add_user_common(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -eq ];then
aciton_false "$1 User:$4 Already Exist."
else
USERID=`awk '{print$1}' ${WORKDIR}/temp/user_info.temp`
for ((i=;i++;i<=));do
echo $USERID | grep -qw $i && continue
ipmitool -I lanplus -U $ -P $ -H $ user set name $i $ &>/dev/null
ipmitool -I lanplus -U $ -P $ -H $ user set password $i $ &>/dev/null
ipmitool -I lanplus -U $ -P $ -H $ user priv $i &>/dev/null
ipmitool -I lanplus -U $ -P $ -H $ channel setaccess $i callin=on ipmi=on link=on privilege=
ipmitool -I lanplus -U $ -P $ -H $ user enable $i &>/dev/null
if [ ${CHOICE_STEP2} -eq ];then
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ racadm set idrac.users.${i}.Privilege 0x1ff &>/dev/null
fi
ipmitool -I lanplus -U $ -P $ -H $ user test $i $ &>/dev/null
STATUS_RC=$?
break
done
if [ $STATUS_RC -eq ];then
if [ ${CHOICE_STEP2} -eq ];then
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ racadm get BIOS.SysInformation.SystemServiceTag | tail -n1 > ${WORKDIR}/temp/dell_sn.temp
SN=`awk -F "=" '{print$2}' ${WORKDIR}/temp/dell_sn.temp`
else
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -w "Product Serial" | awk -F ":" '{print$2}'`
fi
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###.Add the user's common function###
add_batch_task(){
while true;do
read -p "[Please enter the path to the IP list File]:" FILE_PATH
if [ ! -e ${FILE_PATH} ] || [ -z ${FILE_PATH} ]; then
colour default_red
echo "Error: ${FILE_PATH}: No such file or directory."
colour default
continue
fi
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Adding user.This may take serveral minutes,Please wait......";;
*) continue;;
esac
sed '1d' ${FILE_PATH} > ${WORKDIR}/temp/list.temp >/dev/null
while read line;do
IP=`echo $line | awk '{print $1}'`
chenck_ip_port ${IP}
if [ $? -ne ];then
continue
fi
LOGIN_USERNAME=`echo $line | awk '{print $2}'`
LOGIN_PASSWORD=`echo $line | awk '{print $3}'`
NEW_USERNAME=`echo $line | awk '{print $4}'`
NEW_PASSWORD=`echo $line | awk '{print $5}'`
if [ ${CHOICE_STEP2} -eq ];then
add_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $NEW_USERNAME $NEW_PASSWORD
elif [ ${CHOICE_STEP2} -eq ];then
add_user_inspur $IP $LOGIN_USERNAME $LOGIN_PASSWORD $NEW_USERNAME $NEW_PASSWORD
elif [ ${CHOICE_STEP2} -eq ];then
add_user_hp $IP $LOGIN_USERNAME $LOGIN_PASSWORD $NEW_USERNAME $NEW_PASSWORD
elif [ ${CHOICE_STEP2} -eq ];then
add_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $NEW_USERNAME $NEW_PASSWORD
elif [ ${CHOICE_STEP2} -eq ];then
check_dell_ipmi $IP $LOGIN_USERNAME $LOGIN_PASSWORD
add_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $NEW_USERNAME $NEW_PASSWORD
fi
done < ${WORKDIR}/temp/list.temp
break
done
} ###3.1/3.2/3.3/3.4/.5Modify Lenovo, Inspur, HP, Huawei, Dell server user password###
update_user_common(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
USER_ID=`ipmitool -I lanplus -U $ -P $ -H $ user list | grep -w "$UPDATE_USERNAME" | awk '{print$1}'`
ipmitool -I lanplus -U $ -P $ -H $ user set password $USER_ID $ &>/dev/null
ipmitool -I lanplus -U $ -P $ -H $ user test $USER_ID $ &>/dev/null
if [ $? -eq ];then
if [ ${CHOICE_STEP3} -eq ];then
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ racadm get BIOS.SysInformation.SystemServiceTag | tail -n1 > ${WORKDIR}/temp/dell_sn.temp
SN=`awk -F "=" '{print$2}' ${WORKDIR}/temp/dell_sn.temp`
else
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -w "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
fi
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###.Modifying the user password public function###
update_batch_task(){
while true;do
read -p "[Please enter the path to the IP list File]:" FILE_PATH
if [ ! -e ${FILE_PATH} ] || [ -z ${FILE_PATH} ];then
colour default_red
echo "Error: ${FILE_PATH}: No such file or directory."
colour default
continue
fi
sed '1d' ${FILE_PATH} > ${WORKDIR}/temp/list.temp >/dev/null
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Updating user.This may take serveral minutes,Please wait......";;
*) continue;;
esac
while read line;do
IP=`echo $line | awk '{print $1}'`
chenck_ip_port ${IP}
if [ $? -ne ];then
continue
fi
LOGIN_USERNAME=`echo $line | awk '{print $2}'`
LOGIN_PASSWORD=`echo $line | awk '{print $3}'`
UPDATE_USERNAME=`echo $line | awk '{print $4}'`
NEW_PASSWORD=`echo $line | awk '{print $5}'`
if [ ${CHOICE_STEP3} -eq ];then
check_dell_ipmi $IP $LOGIN_USERNAME $LOGIN_PASSWORD
fi
update_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $UPDATE_USERNAME $NEW_PASSWORD
done < ${WORKDIR}/temp/list.temp
break
done
} ###4.1 Delete lenovo server IMM users###
delete_user_lenovo(){
check_port $ $SSH_PORT
if [ $? -ne ];then
aciton_false "$1 TCP 22 Port connection failed."
else
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
USER_ID_LENOVO=`sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ -n "users" | grep -w "$4" | awk '{print$1}'`
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ users -${USER_ID_LENOVO} -clear &> /dev/null
if [ $? -eq ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep "Product Serial" | awk -F ":" '{print$2}'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
fi
} ###4.2 Delete the Inspur server BMS user###
delete_user_inspur(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
USER_ID=`${instool} $ $ $ -lan -user -list |grep -w "$4" | awk '{print$1}'`
${instool} $ $ $ -lan -user -del ${USER_ID}
if [ $? -eq ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep "Product Serial" | awk -F ":" '{print$2}'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###4.3 Delete the HP server BMS user###
delete_user_hp(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ delete /map1/accounts1/$ &> /dev/null
check_user_exist $ $ $ $
if [ $? -ne ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -aw "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###4.4 Delete the HUAWEI server BMS user###
delete_user_huawei(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
/usr/bin/expect << EOF
set timeout
log_user
spawn sshpass -p $ ssh -o StrictHostKeyChecking=no -o LogLevel=quiet ${}@$
expect "*iBMC:/->"
send "ipmcset -t user -d deluser -v ${4}\r"
expect "Input your password:"
send "${3}\r"
expect "*iBMC:/->"
send "exit\r"
expect "*#"
EOF
check_user_exist $ $ $ $
if [ $? -ne ];then
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -aw "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###.Delete server remote management card user common function ###
delete_batch_task(){
while true;do
read -p "[Please enter the path to the IP list File]:" FILE_PATH
if [ ! -e ${FILE_PATH} ] || [ -z ${FILE_PATH} ];then
colour default_red
echo "Error: ${FILE_PATH}: No such file or directory."
colour default
continue
fi
sed '1d' ${FILE_PATH} > ${WORKDIR}/temp/list.temp >/dev/null
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Deleting user.This may take serveral minutes,Please wait......";;
*) continue;;
esac
cat ${WORKDIR}/temp/list.temp | while read line;do
IP=`echo $line | awk '{print $1}'`
chenck_ip_port ${IP}
if [ $? -ne ];then
continue
fi
LOGIN_USERNAME=`echo $line | awk '{print $2}'`
LOGIN_PASSWORD=`echo $line | awk '{print $3}'`
DELETE_USERNAME=`echo $line | awk '{print $4}'`
if [ ${CHOICE_STEP4} -eq ];then
delete_user_lenovo $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DELETE_USERNAME
elif [ ${CHOICE_STEP4} -eq ];then
delete_user_inspur $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DELETE_USERNAME
elif [ ${CHOICE_STEP4} -eq ];then
delete_user_hp $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DELETE_USERNAME
elif [ ${CHOICE_STEP4} -eq ];then
delete_user_huawei $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DELETE_USERNAME
fi
done
break
done
} ###5.1/5.2/5.3/5.4/5.5 Disable Lenovo, Inspur, HP, Huawei, Dell server user###
disable_user_common(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
USER_ID=`ipmitool -I lanplus -U $ -P $ -H $ user list | grep -w "${DISABLE_USERNAME}" | awk '{print$1}'`
ipmitool -I lanplus -U $ -P $ -H $ user disable $USER_ID &>/dev/null
if [ $? -eq ];then
if [ ${CHOICE_STEP5} -eq ];then
SN=`sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet ${}@$ racadm get BIOS.SysInformation.SystemServiceTag | tail -n1 | awk -F "=" '{print$2}'`
else
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -w "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
fi
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###. Disable server remote management card user common function ###
disable_batch_task(){
while true;do
read -p "[Please enter the path to the IP list File]:" FILE_PATH
if [ ! -e ${FILE_PATH} ] || [ -z ${FILE_PATH} ];then
colour default_red
echo "Error: ${FILE_PATH}: No such file or directory."
colour default
continue
fi
sed '1d' ${FILE_PATH} >${WORKDIR}/temp/list.temp >/dev/null
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Disabling user.This may take serveral minutes,Please wait......";;
*) continue;;
esac
while read line;do
IP=`echo $line | awk '{print $1}'`
chenck_ip_port ${IP}
if [ $? -ne ];then
continue
fi
LOGIN_USERNAME=`echo $line | awk '{print $2}'`
LOGIN_PASSWORD=`echo $line | awk '{print $3}'`
DISABLE_USERNAME=`echo $line | awk '{print $4}'`
if [ ${CHOICE_STEP5} -eq ];then
check_dell_ipmi $IP $LOGIN_USERNAME $LOGIN_PASSWORD
fi
disable_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DISABLE_USERNAME
done < ${WORKDIR}/temp/list.temp
break
done
} ###6.1/6.2/6.3/6.4/6.5 enable Lenovo, Inspur, HP, Huawei, Dell server user###
enable_user_common(){
check_login_username_passwd $ $ $
if [ $? -ne ];then
aciton_false "$1 Incorrect Login account."
else
check_user_exist $ $ $ $
if [ $? -ne ];then
aciton_false "$1 User:$4 Not Exists."
else
USER_ID=`ipmitool -I lanplus -U $ -P $ -H $ user list | grep -w "${DISABLE_USERNAME}" | awk '{print$1}'`
ipmitool -I lanplus -U $ -P $ -H $ user enable $USER_ID &>/dev/null
if [ $? -eq ];then
if [ ${CHOICE_STEP6} -eq ];then
sshpass -p $ ssh -o StrictHostKeyChecking=no -n -o LogLevel=quiet $@$ racadm get BIOS.SysInformation.SystemServiceTag | tail -n1 > ${WORKDIR}/temp/dell_sn.temp
SN=`awk -F "=" '{print$2}' ${WORKDIR}/temp/dell_sn.temp`
else
SN=`ipmitool -I lanplus -U $ -P $ -H $ fru list | grep -w "Product Serial" | awk -F ":" '{print$2}' | head -n1 | sed 's#[[:space:]]##g'`
fi
action_true "$1 SN:$SN User:$4"
else
aciton_false "$1 Unknown Error."
fi
fi
fi
} ###. enable server remote management card user common function ###
enable_batch_task(){
while true;do
read -p "[Please enter the path to the IP list File]:" FILE_PATH
if [ ! -e ${FILE_PATH} ] || [ -z ${FILE_PATH} ];then
colour default_red
echo "Error: ${FILE_PATH}: No such file or directory."
colour default
continue
fi
sed '1d' ${FILE_PATH} > ${WORKDIR}/temp/list.temp >/dev/null
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Enabling user.This may take serveral minutes,Please wait......";;
*) continue;;
esac
while read line;do
IP=`echo $line | awk '{print $1}'`
chenck_ip_port ${IP}
if [ $? -ne ];then
continue
fi
LOGIN_USERNAME=`echo $line | awk '{print $2}'`
LOGIN_PASSWORD=`echo $line | awk '{print $3}'`
DISABLE_USERNAME=`echo $line | awk '{print $4}'`
if [ ${CHOICE_STEP6} -eq ];then
check_dell_ipmi $IP $LOGIN_USERNAME $LOGIN_PASSWORD
fi
enable_user_common $IP $LOGIN_USERNAME $LOGIN_PASSWORD $DISABLE_USERNAME
done < ${WORKDIR}/temp/list.temp
break
done
} ###.query user action###
step1_1(){
enter_account_ip
query_user_list
} step1_5(){
enter_account_ip
check_dell_ipmi $IP $USERNAME $PASSWORD
query_user_list
}
###.add user action###
step2_1(){
add_batch_task
echo -e "\nIt's Completed."
rm -f ${WORKDIR}/temp/*.temp
} ###3.update user action###
step3_1(){
update_batch_task
echo -e "\nIt's Completed."
rm -f ${WORKDIR}/temp/*.temp
} ###4.delete user action###
step4_1(){
delete_batch_task
echo -e "\nIt's Completed."
rm -f ${WORKDIR}/temp/*.temp
} ###5.disable user action###
step5_1(){
disable_batch_task
echo -e "\nIt's Completed."
rm -f ${WORKDIR}/temp/*.temp
} ###6.enable user action###
step6_1(){
enable_batch_task
echo -e "\nIt's Completed."
rm -f ${WORKDIR}/temp/*.temp
} ###Two level menu1###
menu_level2(){
cat << EOF
--------------------------------------------------------------
[${CHOICE_STEP0}1] ## For Lenovo SystemX
[${CHOICE_STEP0}2] ## For Inspur YingXin
[${CHOICE_STEP0}3] ## For HP ProLiant
[${CHOICE_STEP0}4] ## For Huawei RH
[${CHOICE_STEP0}5] ## For DELL PowerEdge
[01] ## Return To Previous Menu...
[00] ## Exit
--------------------------------------------------------------
EOF
} ###Two level menu2###
menu_level2_1(){
cat << EOF
--------------------------------------------------------------
[${CHOICE_STEP0}1] ## For Lenovo SystemX
[${CHOICE_STEP0}2] ## For Inspur YingXin
[${CHOICE_STEP0}3] ## For HP ProLiant
[${CHOICE_STEP0}4] ## For Huawei RH
[01] ## Return To Previous Menu...
[00] ## Exit
--------------------------------------------------------------
EOF
} ###query user###
step1(){
while true;do
menu_level2
read -p "Input Your Choice:" CHOICE
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE}]";sleep 1;;
*) CHOICE="other";;
esac
case ${CHOICE} in
11) step1_1;exit 0;;
12) step1_1;exit 0;;
13) step1_1;exit 0;;
14) step1_1;exit 0;;
15) step1_5;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) echo "You've quit the program.";exit 0;;
*) clear;;
esac
done
} ###add user###
step2(){
while true;do
menu_level2
read -p "Input Your Choice:" CHOICE_STEP2
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP2}]";sleep 1;;
*) CHOICE_STEP2="other";;
esac
case ${CHOICE_STEP2} in
21) step2_1;exit 0;;
22) step2_1;exit 0;;
23) step2_1;exit 0;;
24) step2_1;exit 0;;
25) step2_1;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) echo "You've quit the program.";exit 0;;
*) clear;;
esac
done
} ###update user###
step3(){
while true;do
menu_level2
read -p "Input Your Choice:" CHOICE_STEP3
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP3}]";sleep 1;;
*) CHOICE_STEP3="other";;
esac
case ${CHOICE_STEP3} in
31) step3_1;exit 0;;
32) step3_1;exit 0;;
33) step3_1;exit 0;;
34) step3_1;exit 0;;
35) step3_1;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) exit 0;;
*) clear;;
esac
done
} ###delete user###
step4(){
while true;do
menu_level2_1
read -p "Input Your Choice:" CHOICE_STEP4
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP4}]";sleep 1;;
*) CHOICE_STEP4="other";;
esac
case ${CHOICE_STEP4} in
41) step4_1;exit 0;;
42) step4_1;exit 0;;
43) step4_1;exit 0;;
44) step4_1;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) exit 0;;
*) clear;;
esac
done
} ###disable user###
step5(){
while true;do
menu_level2
read -p "Input Your Choice:" CHOICE_STEP5
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP5}]";sleep 1;;
*) CHOICE_STEP5="other";;
esac
case ${CHOICE_STEP5} in
51) step5_1;exit 0;;
52) step5_1;exit 0;;
53) step5_1;exit 0;;
54) step5_1;exit 0;;
55) step5_1;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) exit 0;;
*) clear;;
esac
done
} ###enable user###
step6(){
while true;do
menu_level2
read -p "Input Your Choice:" CHOICE_STEP6
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP6}]";sleep 1;;
*) CHOICE_STEP6="other";;
esac
case ${CHOICE_STEP6} in
61) step6_1;exit 0;;
62) step6_1;exit 0;;
63) step6_1;exit 0;;
64) step6_1;exit 0;;
65) step6_1;exit 0;;
01) clear;menu_level1_action;exit 0;;
00) exit 0;;
*) clear;;
esac
done
} ###First level menu###
menu_level1(){
cat << EOF
##############################################################
# BMC Accounts Batch MGT Tool V1.0.0 #
# Release Date:2017-11-1     #
# NOTE: This script is user to manage the PC server remote #
# management cart account.for Lenovo SystemX,Inspur Yingxin, #
# HP ProLiant,Huawei RH,DELL PowerEdage.     #
# --XX.Tech ITDC itop_Mon #
##############################################################
--------------------------------------------------------------
[1] ## Query user
[2] ## Add user
[3] ## Update user
[4] ## Remove user
[5] ## Disable user
[6] ## Enable user
[0] ## Exit
--------------------------------------------------------------
EOF
} ###First level menu action###
menu_level1_action(){
while true;do
clear;menu_level1
read -p "Input Your Choice(m for help):" CHOICE_STEP0
read -p "Are You Sure?(y/n):" ANSWER
case ${ANSWER} in
y|Y|yes|YES) echo "Your Choice Is:[${CHOICE_STEP0}]";sleep 1;;
*) CHOICE_STEP0="other";;
esac
case ${CHOICE_STEP0} in
1) step1;exit 0;;
2) step2;exit 0;;
3) step3;exit 0;;
4) step4;exit 0;;
5) step5;exit 0;;
6) step6;exit 0;;
m|M) useage;;
0) exit 0;;
*) clear;;
esac
done
} ###User permission check###
if [ `id -u` -ne 0 ];then
action "FAILED: Please Login As Root To Run This Script!" /bin/false
exit 110
fi ###Operating system version check###
if [ `cat /etc/redhat-release | egrep -c "6.4|6.5|6.6|6.8"` -eq 0 ]; then
action "FAILED: Please Run This Script On RHEL6.8!" /bin/false
exit 110
fi ###sshpass packet inspection###
SSHPASS=`rpm -qa | grep -wc sshpass`
if [ ${SSHPASS} -eq 0 ];then
action "Please install the sshpass package." /bin/false
exit 110
fi ###expect packet inspection###
rpm -qa | grep -qw expect
if [ $? -ne 0 ];then
action "Please install the expect package." /bin/false
exit 110
fi ###ipmitool check###
IPMITOOL_VERSION=`rpm -qa | grep -w ipmitool | awk -F "-" '{print$2}'`
if [ -z ${IPMITOOL_VERSION} ];then
action "There is no IPMITOOL installed in the local system." /bin/false
exit 110
elif [ "${IPMITOOL_VERSION}" != "1.8.15" ];then
action "Please update the IPMITOOL version to 1.8.15" /bin/false
exit 110
fi ###Program entrance###
menu_level1_action

PC Server远程管理卡用户管理脚本实现的更多相关文章

  1. 使用mysqlbinlog server远程备份binlog的脚本

    #注意,备份机到远程mysql服务器需要免密钥登录,此脚本放到计划任务中每五分钟执行一次,避免mysqlbinlog server进程长时间挂掉无人知晓   cat backup_binlog.sh ...

  2. 【shell 练习4】编写Shell用户管理脚本(二)

    一.创建.删除.查看用户,随机生成八位数密码 #!/bin/bash #Author:yanglt #!/bin/bash #Author:yanglt #Blog:https://www.cnblo ...

  3. 【shell 练习3】用户管理脚本(一)

    一.创建十个用户,密码为八位 [root@localhost ~]# cat UserManger02.sh #!/bin/bash . /etc/init.d/functions [ $UID -n ...

  4. 管理Windows Server 2008本地用户和组

    下面介绍Windows Server 2008本地用户和组的管理包括创建用户.删除用户.重设密码.将用户添加到组.普通用户跟管理员的区别 .用户配置文件包括桌面上文件,桌面背景,桌面上图标,IE设置, ...

  5. linux高频操作: host,用户管理,免密登陆,管道,文件权限,脚本,防火墙,查找

    1. 修改hosts和hostname 2. 用户管理 3. 免秘登陆 4. 文件末尾添加 >> 5. 设置可执行文件 6. 任何地方调用 7. Centos6 永久关闭防火墙 8. Ce ...

  6. 本地sh脚本创建以及利用ssh server远程运行sh脚本

    想要同时运行多个非本地的sh脚本,用来实现运行同一网段下多机程序的集成,可以通过在每台机器上写sh脚本,再在本机上运行一个启动远程机器sh的脚本 首先需要在所有机器上安装openssh-server ...

  7. shell脚本之用户管理

    #!/usr/bin/env bash ############################### # 脚本名称 : userManager.sh # # 脚本功能 : 账号管理 # # 脚本参数 ...

  8. Windows Server 2008 R2入门之用户管理

    一.用户账户概述: ”用户”是计算机的使用者在计算机系统中的身份映射,不同的用户身份拥有不同的权限,每个用户包含一个名称和一个密码: 在Windows中,每个用户帐户有一个唯一的安全标识符(Secur ...

  9. Linux实战教学笔记14:用户管理初级(下)

    第十四节 用户管理初级(下) 标签(空格分隔): Linux实战教学笔记-陈思齐 ---更多资料点我查看 1,用户查询相关命令id,finger,users,w,who,last,lastlog,gr ...

随机推荐

  1. 去重算法-hash-set

    Well, as Bavarious pointed out in a comment, Apple's actual CoreFoundation source is open and availa ...

  2. python图形库(1)

    python有很好图形库cv2(包含很多图形处理的算法),pylab(绘图工具模块) 这两个“模块”是肯定要配置的. 安装这两个模块可用了我不少时间. pylab它不是一个包,而是 numpy, sc ...

  3. 使用node.js + socket.io + redis实现基本的聊天室场景

    在这篇文章Redis数据库及其基本操作中介绍了Redis及redis-cli的基本操作. 其中的publish-subscribe机制应用比较广泛, 那么接下来使用nodejs来实现该机制. 本文是对 ...

  4. 为什么实例没有prototype属性?什么时候对象会有prototype属性呢?

    为什么实例没有prototype属性?什么时候对象会有prototype属性呢? javascript loudou 1月12日提问 关注 9 关注 收藏 6 收藏,554 浏览 问题对人有帮助,内容 ...

  5. 121. Best Time to Buy and Sell Stock——Leetcode

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  6. fastjson 应用

    fastjson优势就是解析快,用法和json-lib.jar差不多(如下图) 贴心的附上jar和反编译工具:https://pan.baidu.com/s/1iADAiFyoUZVBAFSPsIeY ...

  7. ReactiveCocoa实战: 模仿 "花瓣",重写 LeanCloud Rest Api的iOS REST Client.

    这一次我们将要讨论的是移动开发中比较重要的一环--网络请求的封装.鉴于个人经验有限,本文将在一定程度上参考 基于AFNetworking2.0和ReactiveCocoa2.1的iOS REST Cl ...

  8. 【杂题总汇】UVa-10618 Tango Tango Insurrection

    [UVa-10618] Tango Tango Insurrection ◇ 题目 +vjudge 链接+ (以下选自<算法竞赛入门经典>-刘汝佳,有删改) <题目描述> 你想 ...

  9. 没有CTO的Netflix有哪些值得我们学习的工程文化?

    作者介绍: 杨波,拍拍贷基础框架研发总监.具有超过 10 年的互联网分布式系统研发和架构经验,曾先后就职于:eBay 中国研发中心(eBay CDC),任资深研发工程师,参与亿贝开放 API 平台研发 ...

  10. LINUX安装好后无法访问网络

    LINUX安装好后无法访问网络 在虚拟机安装好新的LINUX系统后,ping www.baidu.com ,发现无法ping通. 键入ifconfig查询配置: eno16777728: flags= ...