-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower_action.sh
75 lines (68 loc) · 2.83 KB
/
power_action.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
CMDB_URL=
CMDB_USER=
CMDB_PASSWORD=
DELL_USER="root"
DELL_PASS="123456"
HP_USER="admin"
HP_PASS="123456"
curl -sD cookie -d "username=$CMDB_USER&password=$CMDB_PASSWORD" http://$CMDB_URL/user/logincheck > /dev/null 2>&1
#racadm serveraction
#graceshutdown - perform a graceful shutdown of server
#powerdown - power server off
#powerup - power server on
#powercycle - perform server power cycle
#hardreset - force hard server power reset
#powerstatus - display current power status of server
#ipmitool
#chassis power Commands: status, on, off, cycle, reset, diag, soft
usage() {
echo -e "Usage: sh $0 {iplist} {serveraction:reboot,poweron,poweroff,status}"
}
if [[ $# -eq 2 ]];then
for SYSIP in `cat $1`
do
BRAND=`curl -sb cookie http://$CMDB_URL/cmdb/hosts/?first_ip=$SYSIP|grep -oP '(?<=device_brand":").+?(?=","device_model)'`
#BRAND=HP
sleep 1;IP=`echo $SYSIP|sed 's/10.209/172.16/'`;echo $IP
if [[ $BRAND =~ "HP" ]];then
case $2 in
poweron)
/usr/bin/ipmitool -H $IP -I lanplus -A PASSWORD -U $HP_USER -P $HP_PASS power on
;;
poweroff)
/usr/bin/ipmitool -H $IP -I lanplus -A PASSWORD -U $HP_USER -P $HP_PASS power off
;;
reboot)
/usr/bin/ipmitool -H $IP -I lanplus -A PASSWORD -U $HP_USER -P $HP_PASS power cycle
;;
status)
/usr/bin/ipmitool -H $IP -I lanplus -A PASSWORD -U $HP_USER -P $HP_PASS power status
;;
*)
echo "action $2 is not supported...";exit 1
esac
elif [[ $BRAND =~ "Dell" ]];then
case $2 in
poweron)
/opt/dell/srvadmin/sbin/racadm -u$DELL_USER -p$DELL_PASS -r $IP serveraction powerup
;;
poweroff)
/opt/dell/srvadmin/sbin/racadm -u$DELL_USER -p$DELL_PASS -r $IP serveraction powerdown
;;
reboot)
/opt/dell/srvadmin/sbin/racadm -u$DELL_USER -p$DELL_PASS -r $IP serveraction powercycle
;;
status)
/opt/dell/srvadmin/sbin/racadm -u$DELL_USER -p$DELL_PASS -r $IP serveraction powerstatus
;;
*)
echo "action $2 is not supported...";exit 1
esac
else
echo "BRAND $BRAND is wrong...";exit 1
fi
done
else
usage
fi