Last active
December 26, 2015 00:09
-
-
Save ailinykh/7061969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER='root' | |
PASSWORD='qwerty' | |
# function 1 | |
function send_message_to_ip { | |
IP=$1 | |
COUNT=$(ping -c 2 $IP | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') | |
if [ $COUNT -eq 0 ] | |
then | |
echo "ip $IP seems to be down" | |
else | |
#send command | |
RESPONSE=$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD raw 0x2e 0x01 0xa2 0x02 0x00) | |
#echo "RESPONSE=$RESPONSE" | |
BYTE=$( echo "$RESPONSE" | awk '{ print $4 }' ) | |
#echo $BYTE $USER $PASSWORD $IP | |
send_message $IP $USER $PASSWORD 3 'NOC' 'qwerty' 2 | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD raw 0x2e 0x03 0xa2 0x02 0x00 0x$BYTE 0x04 0x03 0x00 0x00 0x01 0x09 0x00 0x01 0x01 0x00 0x01 0x00 0x00 0x00 > /dev/null) | |
send_message $IP $USER $PASSWORD 4 'sysadmins' 'qwerty' 2 | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD raw 0x2e 0x03 0xa2 0x02 0x00 0x"$BYTE" 0x04 0x04 0x00 0x00 0x01 0x09 0x00 0x01 0x01 0x00 0x01 0x00 0x00 0x00 > /dev/null) | |
send_message $IP $USER $PASSWORD 5 'DPC' 'qwerty' 2 | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD raw 0x2e 0x03 0xa2 0x02 0x00 0x"$BYTE" 0x04 0x05 0x00 0x00 0x01 0x09 0x00 0x01 0x01 0x00 0xff 0x01 0x00 0x00 > /dev/null) | |
echo "ip $IP is ok" | |
fi | |
} | |
# function 2 | |
function send_message { | |
IP=$1 | |
ID=$4 | |
NAME=$5 | |
USER_PASSWORD=$6 | |
PRIVELEGE_ID=$7 | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD user set name $ID $NAME) | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD user set password $ID $USER_PASSWORD) | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD user enable $ID) | |
$(ipmitool -I lanplus -H $IP -U $USER -P $PASSWORD channel setaccess 1 $ID link=on ipmi=on callin=on privilege=$PRIVELEGE_ID) | |
} | |
# main script body | |
if [ $# -gt 1 ] | |
then | |
PART1=$(echo $1 | awk -F'.' '{ print $1 }') | |
PART2=$(echo $1 | awk -F'.' '{ print $2 }') | |
PART3=$(echo $1 | awk -F'.' '{ print $3 }') | |
START=$(echo $1 | awk -F'.' '{ print $4 }') | |
END=$( echo $2 | awk -F'.' '{ print $4 }') | |
if [ $END -gt $START ] | |
then | |
while [ $START -le $END ] | |
do | |
send_message_to_ip "$PART1.$PART2.$PART3.$START" | |
START=$((START+1)) | |
done | |
else | |
echo "end ip $2 must be greater then start ip $1" | |
fi | |
else | |
if [ $# -gt 0 ] | |
then | |
send_message_to_ip $1 | |
else | |
echo "usage: $0 ip" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment