Advertisement
benaryorg

script02

Feb 5th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.91 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. PASSWDFILE=/etc/passwd
  4.  
  5. print_help()
  6. {
  7.     echo "$0: Usage: $0 [options] | [ login | ps-root ]"
  8.     cat << "END"
  9. Outputs some information, depending on the options.
  10. If no options are specified, the help is printed.
  11.  
  12. Commands: [ login | ps-root ]
  13.   login:   the /etc/passwd line corresponding to the calling user is printed
  14.   ps-root  the lines of the command `ps-root` containing "root" are printed
  15.  
  16. Options: [h]
  17.   -h, --help                        outputs this text
  18. END
  19. }
  20.  
  21. error()
  22. {
  23.     echo $1 >&2
  24.     print_help >&2
  25. }
  26.  
  27. if [ $# -eq 0 ];then
  28.     print_help
  29. elif [ $# -eq 1 ];then
  30.     if [ "x$1" = "xlogin" ];then
  31.         echo $(cat $PASSWDFILE | egrep "$USER")
  32.     elif [ "x$1" = "xps-root" ];then
  33.         ps -ef | sed -e "root"
  34.     elif [ "x$1" = "x-h" ];then
  35.         print_help
  36.     elif [ "x$1" = "x--help" ];then
  37.         print_help
  38.     else
  39.         error "unknown paremeter"
  40.         exit 1
  41.     fi
  42. else
  43.     error "wrong paremeter count"
  44.     exit 1
  45. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement