crowbar/crowbar-core

View on GitHub
bin/ipmi_watch

Summary

Maintainability
Test Coverage
#!/bin/bash
#
# Copyright 2011-2013, Dell
# Copyright 2013-2014, SUSE LINUX Products GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

print_usage() {
 echo " Usage: $0 -h <hostname|ip> -u <username> -p <password>"
}

run_watch() {
  echo " Connecting to BMC console on $1... "
  ipmitool -I lanplus -H "$1" -U "$2" -P "$3" sol activate
}

run_interactive() {
  clear
  read -p " IPMI address : " hostname
  read -p " Username : " username
  prompt=" Password : "
  while read -p "${prompt}" -s -n 1 char ; do 
    if [[ $char == $'\0' ]] ; then
      break
    fi
    prompt='*'
    password+="$char"
  done
  echo
}

if [ $# -eq 0 ] ; then
  run_interactive
else
  while getopts 'h:u:p:--help' OPTION ; do
    case $OPTION in 
    h) hostname="$OPTARG"
      ;;
    u) username="$OPTARG"
      ;;
    p) password="$OPTARG"
      ;;
    *) print_usage && exit 1
      ;;
    esac
  done
  if ! [[ $username && $password  && $hostname ]] ; then
      echo " You have to set a username, password and hostname"
      echo " Run ./$0 --help for more information"
      exit 1
  fi
fi

run_watch "$hostname" "$username" "$password"