should cause waitfor to periodically check for the existence of the indicated file and inform you when it does (by displaying a message or by mail if the -m option is also selected).
Add a -f option to waitfor to have it periodically check for the existence of a file (ordinary file or directory) instead of for a user logging on. So typing:
waitfor -f /usr/spool/steve/newmemo &
There are a lot of changes required to fix how the script parses and tests starting values. For example, you can't just test for a username after getopts because if you're checking for a file, you don't need to also validate a username. Biggest change is the addition of the variable waitfile and all the tests and changes it causes:
#
# Wait until a specified user logs on -- version 4
#
# Set up default values
mailopt=FALSE
interval=60
waitfile=""
# process command options
while getopts "f:mt:" option
do
case "$option"
in
f) waitfile=$OPTARG ;;
m) mailopt=TRUE ;;
t) interval=$OPTARG ;;
\?) echo "Usage: waitfor [-f] [-m] [-t n] user"
echo " -f FILE means wait for the FILE to be created"
echo " -m means to be informed by mail"
echo " -t N means check every n secs."
exit 1;;
esac
done
# Make sure a user name was specified
if [ "$OPTIND" -gt "$#" -a -z "$waitfile" ] ; then
echo "Missing user name!" ; exit 2
fi
shiftcount=$(( $OPTIND - 1 ))
shift $shiftcount
user=$1
# Check for user logging on or for the file to appear
if [ -n $waitfile ] ; then
until test -e $waitfile ; do
sleep $interval
done
else
until who | grep "^$user " > /dev/null ; do
sleep $interval
done
fi
# When we reach this point, the user has logged on
device=$( who | grep "^$user " | cut -c10-16)
if [ "$mailopt" = FALSE ] ; then
if [ -n "$waitfile" ] ; then
echo "File $waitfile now exists"
else
echo "$user has logged on to $device"
fi
else
recipient=$(who am i | cut -cl-8)
if [ -n "$waitfile" ] ; then
echo "File $waitfile now exists" | mail $recipient
else
echo "$user has logged on to $device" | mail $recipient
fi
fi
exit 0
You might also like to view...
Answer the following statements true (T) or false (F)
1) An interface cannot declare any instance variables. 2) Establishing the relationship between a listener and the component it listens to is accomplished using polymorphism. 3) A reference variable can refer to an object of a child class, but not any further down the inheritance hierarchy. 4) Polymorphism via inheritance requires that all classes in the inheritance hierarchy are concrete. 5) An interface name may be used as a reference type.
Forms may include ________ controls, which are decorative or design elements, but not connected to a data source
Fill in the blank(s) with correct word
The error ________ will display when a formula attempts to divide a value by zero or an empty cell
Fill in the blank(s) with correct word
To execute a program one statement at a time without entering the code of a called method, use the debugger’s__________ command.
a) Step Under b) Step Over c) Step Into d) Step Out Of