sispmctl – control a terminal server

Hello,
a terminal server is very useful in a Cisco lab. To be usefull it should be up and running, but keep it switched on 24/7 is not an option in a home lab. With a Gembird SIS-PM programmable power outlet it could be switched on when its needed and switched off if the lab is done and it is time to go to bed or to work (after a long night of configuring, testing and debuging).

This post is a followup to this three posts:

I created two scripts , one to switch the the terminal server on and one to switch it off.

#!/bin/sh
# r2511a_on
# 20120211 crissa for http://blog.rotten.li

if [ `sispmctl -q -n -g 4` == "0" ]
then
  echo "r2511a: status off"

  sispmctl -q -o 4

  echo "r2511a: switched on, booting ..."
  sleep 60

  export FTOO=1
fi

if [ `sispmctl -q -n -g 4` == "1" ]
then
  if [ `alive r2511a` == "0" ]
  then
    echo "r2511a: status on and alive!"
  else
    # echo "r2511a: status on and not alive"
    
    while [ `alive r2511a` == "1" ]
    do
      # echo "wait 10 sec ..."
      echo "r2511a: status on and not alive, wait 10 sec ..."
      sleep 10
    done

    if [ "$FTOO" == "1" ]
    then
      echo "r2511a: wait 30 sec ... (almost there)"
      sleep 30
    fi

    echo "r2511a: status on and alive!"
  fi
fi

# eof

The terminal server, a Cisco 2511 router, needs around 90 to 100 seconds to boot, so script sleeps for 60 seconds after the terminal server was switched on. If the terminal server is already running the script will return to the shell prompt without further delay. The router can’t be reached by telnet as soon as it is ping able, it still has some work to do, so the script sleeps for 30 seconds.

#!/bin/sh
# r2511a_off
# 20120211 crissa for http://blog.rotten.li

if [ `sispmctl -q -n -g 4` == "1" ]
then
  echo "r2511a: status on"
  
  CNT=`snmpwalk -v 2c -c public r2511a 1.3.6.1.4.1.9.2.9.2.1.1 | grep "INTEGER: 1" | wc -l`
  while [ $CNT -gt 0 ]
  do
    echo "r2511a: status on, $CNT user(s) connected, waiting 20 sec ..."
    sleep 20
    CNT=`snmpwalk -v 2c -c public r2511a 1.3.6.1.4.1.9.2.9.2.1.1 | grep "INTEGER: 1" | wc -l`
  done

  sispmctl -q -f 4

  echo "r2511a: switched off, wait 5 sec ..."
  sleep 5
fi

if [ `sispmctl -q -n -g 4` == "0" ]
then
  echo "r2511a: status off"
fi

# eof

Instead of just switching the terminal server off the script first checks if the terminal server is used. As long as it is used the script will check, sleep, check again, sleep again and so on. As soon as the terminal server is unused the script will switch off the terminal server.

The main reason for this scripts was to use the terminal server while I’m not at home. The terminal server is always connected to port 4 of the power outlet. I use port 3 of the power outlet to switch on and off my current lab (at the moment two Cisco 1712 routers and one Cisco 2520 router).

HTH!
Bye, Tore

This entry was posted in Cisco, General, Linux and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *