HI can someone help me figure out why i'm getting expr errors and that OPTIND doesn't show anything when run in debug mode. OPTIND is set to 1 under set.
#!/bin/sh
#
Wait until a specified user logs on -- Version 3
#
Set up default values
mailopt=FALSE
fileopt=FALSE
interval=60
process command line options
while getopts mt: option
do
case "$option"
in
m) mailopt=TRUE;;
f) fileopt=TRUE;;
t) interval=$OPTARG;;
\?) echo "Usage: move [-f] [-m] [-t n] user"
echo " -m means to be informed by email"
echo " -f means to check for file"
echo " -t means check every n secs."
exit 1;;
esac
done
Make sure a user name was specified
echo $OPTIND
if [ "$OPTIND" -gt "$#" ]
then
echo "Missing user name!"
exit 2
fi
shiftcount=expr $OPTIND - 1
shift $shiftcount
user=$1
#
Check for user logging on or a created file
#
if [ "$fileopt" = FALSE ]
then
until who | grep "$user " > /dev/null
do
sleep $interval
echo " moving on !"
done
else
until ls -l | grep "$user /$" > /dev/null
do
sleep $interval
done
fi
#
When we reach this point, the user has logged on
#
if [ "$mailopt" = FALSE ]
then
echo "$user has logged on"
else
runner=who am i | cut -c1-8
echo "$user has logged on" | mail $runner
fi