:::::::::::::: lookup :::::::::::::: #!/bin/bash # # CIS 130 Lab 5 - lookup (enhanced) # # Rich Simms # Spring 2007 # # This script lookups a user in /etc/passwd and prints user name and uid # # usage: lookup [-d] user # # Initialize usage="lookup [-d] user" # Process debug option (-d) while getopts ":d" opt; do case $opt in d ) debug="y" echo "** Debug tracing enabled" ;; \? ) echo "-- Usage: " $usage >&2 exit 1 esac done # Shift out any options if [ $OPTIND -ge 1 ]; then shift $(($OPTIND - 1)); fi user=$1 if [ "$user" = "" ]; then echo "-- Usage: " $usage >&2 exit 1 fi if [ "$debug" = "y" ]; then echo "** trace: user = " $user fi while read inputline do login="$(echo $inputline | cut -d: -f1)" uid="$(echo $inputline | cut -d: -f3)" fulln="$(echo $inputline | cut -d: -f5)" if [ "$debug" = "y" ]; then echo "** trace: login=$login, uid=$uid, fulln=$fulln" fi if [ $login = $user ]; then echo "$fulln: $uid"; exit 0; fi done < /etc/passwd echo "User:" $user "not found in /etc/passwd" exit 0 :::::::::::::: lpm :::::::::::::: #!/bin/bash # # CIS 130 Lab 5 - lpm # # Rich Simms # Spring 2007 # # This script takes a pathname and prints out a long listing of each directory # in the path as well as the file at the end. # # usage: lpm [-d] user # # Initialize usage="lpm [-d] path" debug=n # Process debug option (-d) while getopts ":d" opt; do case $opt in d ) debug=y echo "** Debug tracing enabled" ;; \? ) echo "-- Usage: " $usage exit 1 esac done # Shift out any options if [ $OPTIND -ge 1 ]; then shift $(($OPTIND - 1)); fi path=$1 if [ "$path" = "" ]; then echo "-- Usage: " $usage exit 1 fi if [ $debug = y ] ; then echo "** trace: path = " $path echo "** trace: debug = " $debug fi IFS=/ set $path if [ $debug = y ] ; then echo "** trace: \$@ = " "$@" ; fi if [ $debug = y ] ; then echo "** trace: \$# = " $# ; fi # check if absolute path if [ "$1" = "" ] ; then cd / if [ $debug = y ] ; then echo "current directory is: " "$PWD"; fi if [ $debug = y ] ; then echo "\$1 = " "$1" ; fi ls -ld / shift fi while [ $# -gt 0 ] do if [ $debug = y ] ; then echo "\$1 = " "$1"; fi ls -ld "$1" if [ -d "$1" ] ; then cd $1; fi if [ $debug = y ] ; then echo "current directory is: " "$PWD"; fi shift done exit 0 :::::::::::::: prompts :::::::::::::: PS1='$(pwd) $ ' PS1="$(hostname -s)|$(logname) & " :::::::::::::: query :::::::::::::: #!/bin/bash # # CIS 130 Lab 5 - query # # Rich Simms # Spring 2007 # # This script lookups a user in /etc/passwd and prints user name, uid, # home and shell. # # usage: query [-d] user # # Initialize usage="query [-d] user" debug=n # Process debug option (-d) while getopts ":d" opt; do case $opt in d ) debug=y echo "** Debug tracing enabled" ;; \? ) echo "-- Usage: " $usage >&2 exit 1 esac done # Shift out any options if [ $OPTIND -ge 1 ]; then shift $(($OPTIND - 1)); fi user=$1 if [ "$user" = "" ]; then echo "-- Usage: " $usage >&2 exit 1 fi if [ $debug = y ] ; then echo "** trace: user = " $user echo "** trace: debug = " $debug fi line=$(grep $user /etc/passwd) rc=$? if [ $debug = y ] ; then echo "** trace: line = " $line echo "** trace: rc = " $rc fi if [ $rc = 0 ] ; then IFS=: set $line echo $5 echo "uid: " $3 echo "home directory: " $6 echo "shell: " $7 else echo "User: $user not found" fi exit 0 /home/cis130/simmsric/lab5 $