Monday, August 4, 2014

Shutdown the multiple server using the Blade Logic script

Note: Place this script and a file with list of servers on the same directory on BL server and run the script.
1. The script
#!/opt/bladelogic/NSH/bin/nsh
# How to user it
# create a file with list of servers and save on the same dir as this file is.
# run this script on a blade logic server.
# ./server_shutdown.nsh --check file_with_list_of_servers
USER_CHOICE=$1
SERVER_FILE=$2
if [ -z $USER_CHOICE ]
then
    echo usage: server_shutdown.nsh --check  {file_with_list_of_servers}
    exit 0
fi
if [ -z $SERVER_FILE ]
then
    echo usage: server_shutdown.nsh --check  {file_with_list_of_servers}
    exit 0
fi
if [ ! -f $SERVER_FILE ]
then
    echo file $SERVER_FILE does not exist
    echo please check and try again
    exit 4
fi
if [ "$USER_CHOICE" = "--check" ]
then
    for i in $(cat $SERVER_FILE)
    do
        echo
        echo "======================================================="
        echo shutting down $i
# For Linux server shutdown
        nexec $i shutdown -h now
# For solaris server shutdown
        nexec $i 'init 5'
    done
    echo

else
    # no valid choice
    echo usage: server_shutdown.nsh --check  {file_with_list_of_servers}
fi

2. The file with script
$ more mylist
he3unxdv512
he3unxdv513
he3unxdv514
he3unxdv515
he3unxdv516
he3unxdv517

3. how to use it?
$ ./server_shutdown.nsh --check mylist
bash-3.2$

No comments:

Post a Comment