Frank,

Here's a Linux-centric approach to check that a user ID exists and is 
logged off. It assumes the vmcp module is loaded:

# ./checkuser.sh foo
Error: foo does not exist
# ./checkuser.sh sysmaint
# echo $?
0
# ./checkuser.sh linux191
Error: linux191 is logged on

Here's the code:

# cat checkuser.sh 
#!/bin/sh
#+--------------------------------------------------------------------------+
function CPcmd()
# Run a CP command and invoke it via the vmcp module/command
#   Arg1-n: the command to issue
#   Return: the command's return code
#+--------------------------------------------------------------------------+
 {
  if [ "$verbose" = 2 ]; then  // echo extra output 
    echo "Invoking CP command: $@"
  fi
# parse output to get return code: awk -F# splits line at '#' with rc at 
end
  output=$(vmcp $@ 2>&1)
  if [ ${#output} != 0 -a "$verbose" != 0 ]; then # echo the output
    echo "$output"
  fi
  retVal=0
  retVal=$(echo $output | grep "Error: non-zero CP" | awk -F# '{print 
$2}')
  return $retVal
 }

#+--------------------------------------------------------------------------+
function checkID()
# Verify user ID exists and is logged off
# Arg 1: user ID to check
#+--------------------------------------------------------------------------+
 {
  userID=$1
  verbose=0
  CPcmd QUERY $userID
  rc=$?
  case $rc in
    0)  # user ID is logged on or disconnected
      echo "Error: $userID is logged on"
      return 1
      ;;
    3)  # user ID does not exist
      echo "Error: $userID does not exist"
      return 2
      ;;
   45) # user ID is logged off - this is correct
      ;;
   *) # unexpected
      echo "Error: unexpected rc from CP QUERY $userID - $rc"
      return 3
  esac
  verbose=1
  return 0
 } # checkID()

# main()
checkID $1
exit $?

Hope this helps.

"Mike MacIsaac" <[email protected]>   (845) 433-7061

Reply via email to