PC Server远程管理卡用户管理脚本实现
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远程管理卡用户管理脚本实现的更多相关文章
- 使用mysqlbinlog server远程备份binlog的脚本
#注意,备份机到远程mysql服务器需要免密钥登录,此脚本放到计划任务中每五分钟执行一次,避免mysqlbinlog server进程长时间挂掉无人知晓 cat backup_binlog.sh ...
- 【shell 练习4】编写Shell用户管理脚本(二)
一.创建.删除.查看用户,随机生成八位数密码 #!/bin/bash #Author:yanglt #!/bin/bash #Author:yanglt #Blog:https://www.cnblo ...
- 【shell 练习3】用户管理脚本(一)
一.创建十个用户,密码为八位 [root@localhost ~]# cat UserManger02.sh #!/bin/bash . /etc/init.d/functions [ $UID -n ...
- 管理Windows Server 2008本地用户和组
下面介绍Windows Server 2008本地用户和组的管理包括创建用户.删除用户.重设密码.将用户添加到组.普通用户跟管理员的区别 .用户配置文件包括桌面上文件,桌面背景,桌面上图标,IE设置, ...
- linux高频操作: host,用户管理,免密登陆,管道,文件权限,脚本,防火墙,查找
1. 修改hosts和hostname 2. 用户管理 3. 免秘登陆 4. 文件末尾添加 >> 5. 设置可执行文件 6. 任何地方调用 7. Centos6 永久关闭防火墙 8. Ce ...
- 本地sh脚本创建以及利用ssh server远程运行sh脚本
想要同时运行多个非本地的sh脚本,用来实现运行同一网段下多机程序的集成,可以通过在每台机器上写sh脚本,再在本机上运行一个启动远程机器sh的脚本 首先需要在所有机器上安装openssh-server ...
- shell脚本之用户管理
#!/usr/bin/env bash ############################### # 脚本名称 : userManager.sh # # 脚本功能 : 账号管理 # # 脚本参数 ...
- Windows Server 2008 R2入门之用户管理
一.用户账户概述: ”用户”是计算机的使用者在计算机系统中的身份映射,不同的用户身份拥有不同的权限,每个用户包含一个名称和一个密码: 在Windows中,每个用户帐户有一个唯一的安全标识符(Secur ...
- Linux实战教学笔记14:用户管理初级(下)
第十四节 用户管理初级(下) 标签(空格分隔): Linux实战教学笔记-陈思齐 ---更多资料点我查看 1,用户查询相关命令id,finger,users,w,who,last,lastlog,gr ...
随机推荐
- IOS 制作常用代码的快捷方式
输入可以变的对象或类型,要用<#name#>
- Jenkins配置(Jenkins如何与maven项目进行连用)
一同事,在问关于Jenkins搭建后,他是如何与我们项目进行连用的,如何通过Jenkins去编译我们的项目的,现在介绍下如何通过Jenkins持续编译我们的项目 配置过程 1.确定我们已经搭建好了Je ...
- HDU(4394),数论上的BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4394 思路很巧妙,要找到m,可以这样思考,n的个位是有m的个位决定的,从0-9搜一遍,满足情况的话就继 ...
- 2017.11.18 C语言的算法分析题目
算法分析 1. 选定实验题目,仔细阅读实验要求,设计好输入输出,按照分治法的思想构思算法,选取合适的存储结构实现应用的操作. 2. 设计的结果应在Visual C++ 实验环境下实现并进行调试.(也可 ...
- theano提示:g++ not detected的解决办法
导入theano包后出现如下警告: WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execu ...
- 第42章 电源管理—实现低功耗—零死角玩转STM32-F429系列
第42章 电源管理—实现低功耗 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fir ...
- Spring Bean依赖但注入(autowired或resource)时NullPointerException(xml和annotation混用的场景下)
项目中同时使用了xml和annotation的方式管理Spring Bean 启动时候报NullPointerException,依赖注入失败! 参考: http://fly0wing.iteye.c ...
- python显示灰度图
import matplotlib import matplotlib.pyplot as plt %matplotlib inline im=plt.imread('../lena.jpg', py ...
- 7-4 python 接口开发(提供mock服务)
1.登录接口开发(数据存在数据库中) 接口开发做mock(模拟功能) tools.py import pymysql def my_db(sql): conn = pymysql.connect(h ...
- LNMP+HAProxy+Keepalived负载均衡 - LNMP基础环境准备
环境版本说明: 服务器系统:CentOS 7.5: ``` cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) # 输出结果 `` ...