代码: 全选
#!/bin/sh
#file: lspids.sh
# import trigger_error
. /home/jj/scripts/trigger_error.sh
# Linux OR BSD ?
case `uname` in
Linux) PSCMD="ps -ef" ;;
*BSD) PSCMD="ps -auwx" ;;
*) trigger_error "unknow system" "ERROR"
esac
HEADER=false
while getopts h OPTION
do
case $OPTION in
h) HEADER=true; shift;;
\?) trigger_error "wrong option" "ERROR"
esac
done
if [ -z $1 ];then
trigger_error "you should at least give one argument" ERROR
else
if [ "$HEADER" = true ];then
$PSCMD | head -n 1
fi
$PSCMD | grep $1 | grep -v grep
fi
代码: 全选
#!/bin/sh
#file: find_cmd.sh
find_cmd()
{
FOUND=false
if [ -z $1 ]; then
echo "ERROR"
return 1
fi
OLDIFS="$IFS"
IFS=:
for i in $PATH
do
if [ -f "$i/$1" ]; then
echo "$i/$1"
FOUND=true
fi
done
# see if we have found the cmd
if [ "$FOUND" = false ];then
echo "$1 could not found!"
return 1
fi
IFS=$OLDIFS
return 0
}
代码: 全选
#!/bin/sh
#description: handle error
#file: trigger_error.sh
trigger_error()
{
if [ $# -eq 1 ];then
echo $1
elif [ $# -eq 2 ]; then
case $2 in
FATAL) echo "FATAL ERROR : $1"; exit 1;;
ERROR) echo "ERROR : $1"; exit 1;;
WARM) echo "WARMING : $1";;
*) echo "$2 : $1";;
esac
else
echo $@
fi
}
代码: 全选
#!/bin/sh
# $CMD_PATH is different from "$CMD_PATH"
# file: lscmd
CMD_PATH=/bin/
for i in $CMD_PATH*
do
whatis `basename $i`
done