2013-02-26 14:54:55 +00:00
|
|
|
#!/bin/sh
|
2012-05-07 18:46:25 +00:00
|
|
|
|
|
|
|
# Provide serial console access to nodes
|
|
|
|
|
|
|
|
# To handle cases like running this via sudo, get the home dir properly
|
2012-04-10 02:45:38 +00:00
|
|
|
os=`uname`
|
2012-10-16 16:49:23 +00:00
|
|
|
if [ "$os" == "Linux" ]; then
|
2012-04-10 02:45:38 +00:00
|
|
|
HOME=`getent passwd $(whoami)|cut -d: -f 6`
|
|
|
|
export HOME
|
|
|
|
fi
|
2012-10-16 16:49:23 +00:00
|
|
|
if [ "$os" == "AIX" ]; then
|
2012-05-07 18:46:25 +00:00
|
|
|
HOME=`lsuser -a home $(whoami)|cut -d= -f 2`
|
|
|
|
export HOME
|
|
|
|
fi
|
2012-04-10 02:45:38 +00:00
|
|
|
|
2014-07-28 22:01:19 +00:00
|
|
|
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
|
2008-10-31 15:01:50 +00:00
|
|
|
echo "rcons - remotely accesses the serial console of a node"
|
2009-04-24 10:33:09 +00:00
|
|
|
echo "rcons <singlenode> [conserver] [-f]"
|
2010-03-09 05:45:59 +00:00
|
|
|
echo "rcons <singlenode> [conserver] [-s]"
|
2008-10-31 15:01:50 +00:00
|
|
|
echo "rcons [-h|--help|-v|--version]"
|
|
|
|
exit 0
|
|
|
|
fi
|
2009-09-01 15:55:58 +00:00
|
|
|
if [ "$1" = "-v" ]; then
|
2012-10-16 16:49:23 +00:00
|
|
|
echo "Version 2.8"
|
2008-10-31 15:01:50 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2009-04-24 10:33:09 +00:00
|
|
|
|
|
|
|
if [ -n "$3" ] && [ "$3" = "-f" ]; then
|
|
|
|
FORCE=-f
|
|
|
|
CONSERVER=$2
|
|
|
|
fi
|
|
|
|
|
2010-03-09 05:45:59 +00:00
|
|
|
#console spy mode
|
|
|
|
if [ -n "$3" ] && [ "$3" = "-s" ]; then
|
|
|
|
FORCE=-s
|
|
|
|
CONSERVER=$2
|
|
|
|
fi
|
|
|
|
|
2012-10-16 16:49:23 +00:00
|
|
|
if [ -n "$2" ]; then
|
|
|
|
if [ "$2" = "-f" ]; then
|
|
|
|
FORCE=-f
|
|
|
|
else
|
|
|
|
if [ "$2" = "-s" ]; then
|
|
|
|
FORCE=-s
|
|
|
|
else
|
|
|
|
CONSERVER=$2
|
|
|
|
fi
|
|
|
|
fi
|
2010-03-09 05:45:59 +00:00
|
|
|
fi
|
|
|
|
|
2012-10-16 16:49:23 +00:00
|
|
|
if [ -f "/usr/bin/console" ] || [ -f "/bin/console" ]; then
|
|
|
|
#use conserver
|
|
|
|
if [ -z "$CONSERVER" ]; then
|
2009-11-18 06:24:36 +00:00
|
|
|
CONSERVER=`nodels $1 nodehm.conserver 2>/dev/null | awk -F: '{print $2}' | tr -d ' '`
|
2012-10-16 16:49:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$CONSERVER" ]; then
|
2008-01-10 01:59:16 +00:00
|
|
|
CONSERVER=$XCATHOST
|
2012-10-16 16:49:23 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$CONSERVER" ]; then
|
2008-01-10 01:59:16 +00:00
|
|
|
CONSERVER=localhost
|
2012-10-16 16:49:23 +00:00
|
|
|
fi
|
|
|
|
#NOTE: IPv6 is not good with the below if going by IP, needs more sophisticated
|
|
|
|
#parsing
|
|
|
|
CONSERVER=`echo $CONSERVER|cut -d: -f 1`
|
2009-07-22 05:58:07 +00:00
|
|
|
|
2012-10-16 16:49:23 +00:00
|
|
|
#Detect console support of SSL, only fixup consolerc if encryption is detected
|
|
|
|
if ! console -h 2>&1 | grep "encryption not compiled" > /dev/null; then
|
2014-08-04 14:13:42 +00:00
|
|
|
# generate .consolerc if it does not exist or is empty
|
|
|
|
if [ ! -s $HOME/.consolerc ]; then
|
|
|
|
cat > $HOME/.consolerc << EOF
|
|
|
|
config * {
|
|
|
|
port 782;
|
|
|
|
sslenabled yes;
|
|
|
|
sslauthority $HOME/.xcat/ca.pem;
|
|
|
|
sslcredentials $HOME/.xcat/client-cred.pem;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
fi
|
2012-10-16 16:49:23 +00:00
|
|
|
else
|
|
|
|
# ssl is not enabled, comment out the ssl settings in .consolerc
|
|
|
|
if [ -f $HOME/.consolerc ]; then
|
|
|
|
sed -i 's/\Wssl/#ssl/1' $HOME/.consolerc
|
|
|
|
fi
|
2009-07-22 05:58:07 +00:00
|
|
|
fi
|
2012-10-16 16:49:23 +00:00
|
|
|
|
|
|
|
exec console $FORCE -M $CONSERVER $1
|
|
|
|
else
|
|
|
|
if [[ "$FORCE" == "-s" ]]; then
|
|
|
|
echo "Read-only mode is not supported, please run rcons without -s option."
|
|
|
|
exit 1
|
2010-02-23 05:49:30 +00:00
|
|
|
fi
|
2012-10-16 16:49:23 +00:00
|
|
|
#deal with consoles directly
|
|
|
|
output=`nodels $1 nodehm.conserver nodehm.cons nodehm.mgt 2>&1`
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$CONSERVER" ]; then
|
|
|
|
CONSERVER=`echo "$output"|grep nodehm.conserver|cut -d: -f3|tr -d ' \n'`
|
|
|
|
fi
|
2012-12-13 18:37:40 +00:00
|
|
|
CONS=`echo "$output" |grep /nodehm.cons$/|cut -d: -f3 | tr -d ' \n'`
|
2012-10-16 16:49:23 +00:00
|
|
|
if [ -z "$CONS" ]; then
|
|
|
|
CONS=`echo "$output"|grep nodehm.mgt|cut -d: -f3 | tr -d ' \n'`
|
|
|
|
fi
|
|
|
|
if [ -z "$CONS" ]; then
|
|
|
|
echo "Error: nodehm.mgt or nodehm.cons for node $1 not setup."
|
|
|
|
exit 1;
|
|
|
|
fi
|
2013-02-26 14:54:55 +00:00
|
|
|
|
|
|
|
#check if conserver is local host
|
|
|
|
result=`ping -c1 $CONSERVER 2>&1`
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
index1=`expr index "$result" "\("`
|
|
|
|
index2=`expr index "$result" "\)"`
|
|
|
|
pos=`expr $index1 + 1`
|
|
|
|
length=`expr $index2 - $index1`
|
|
|
|
length=`expr $length - 1`
|
|
|
|
cons_ip=`expr substr "$result" $pos $length`
|
2014-05-08 13:49:39 +00:00
|
|
|
if [ "$os" == "AIX" ]; then
|
|
|
|
ifconfig |grep "$cons_ip"
|
|
|
|
else
|
|
|
|
ip addr |grep "$cons_ip"
|
|
|
|
fi
|
2013-02-26 14:54:55 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
CONSERVER=""
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Error: conserver $CONSERVER is not reachable."
|
|
|
|
exit 1;
|
|
|
|
fi
|
2012-12-13 18:37:40 +00:00
|
|
|
#echo "CONS=$CONS CONSERVER=$CONSERVER"
|
2009-04-24 10:33:09 +00:00
|
|
|
|
2012-10-16 16:49:23 +00:00
|
|
|
# check if others are using the console
|
|
|
|
if [[ -n $CONSERVER ]]; then
|
|
|
|
ssh $CONSERVER ps -ef |grep $1 |grep -v grep |grep "$XCATROOT/share/xcat/cons" > /dev/null
|
|
|
|
else
|
|
|
|
ps -ef |grep $1 |grep -v grep |grep "$XCATROOT/share/xcat/cons" > /dev/null
|
|
|
|
fi
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [[ "$FORCE" == "-f" ]] ; then
|
|
|
|
echo "Only one console can be run at a time for a node. Other consoles will be closed."
|
|
|
|
else
|
|
|
|
echo "Only one console can be run at a time for a node. Please close other consoles or run rcons with -f option."
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "**** Enter ~? for help *****"
|
|
|
|
if [ -z "$XCATROOT" ]; then
|
|
|
|
cmdpath="/opt/xcat/share/xcat/cons"
|
|
|
|
else
|
|
|
|
cmdpath="$XCATROOT/share/xcat/cons"
|
|
|
|
fi
|
|
|
|
if [ -z "$CONSERVER" ]; then
|
|
|
|
exec $cmdpath/$CONS $1
|
|
|
|
else
|
|
|
|
exec ssh -t $CONSERVER "$cmdpath/$CONS $1"
|
|
|
|
fi
|
|
|
|
fi
|