#!/bin/sh
# Script to query and parse the output from "ps" and "who" command

if [ "$1" == "task" ]; then
    task=`ps -t $2 -o lstart,pid,tty,user,ucomm,etime --no-heading`
    rc=$?
    echo $task | awk '{print $2","$3","$4","$5","$6","$7","$8","$9","$10}'
    exit $rc
fi

if [ "$1" == "logoff" ]; then
    pid=`ps ax -o pid,command --no-heading | grep $2 | grep sshd | grep -v grep`
    rc=$?
    if [ $rc -eq 0 ]; then
        pid=`echo $pid | cut -d" " -f1`
        kill -9 $pid
        exit 0
    fi
    exit $rc
fi

if [ "$1" == "kill" ]; then
    pid=`ps ax -o pid | grep $2`
    rc=$?
    if [ $rc -eq 0 ]; then
        kill -9 $pid
        exit 0
    fi
    exit $rc
fi

LC_TIME=en_US who | grep "(" | sed 's/(//;s/)//' | awk '{print $1","$2","$3","$4","$5}' 
rc=$?
exit $rc



