Copy watchfor from
[KP84]
Section 5.3.
Then change watchfor so that multiple arguments are
treated as different people, rather than requiring the user to
type 'joe|mary'.
Example A.1. watchforM
#!/bin/bash # watchfor: watch for someone to log in PATH=/bin:/usr/bin case $# in 0) echo 'Usage: watchfor person' 1>&2; exit 1 esac while x=`who` do for i in $* do echo $x | grep "$i" && echo "YES!" && exit 1 done sleep 10 done
This solution could possibly be refined by moving the inner
of the loop into the while or until.
Experimentation is free, but be careful, you may learn ;-)
Example A.2. watchforM1
Further experiments show:
#!/bin/bash # watchfor: watch for someone to log in PATH=/bin:/usr/bin case $# in 0) echo 'Usage: watchfor person' 1>&2; exit 1 esac until x=`who`; for i in $*; do echo $x | grep $i && exit 0; done do sleep 10 done
Copy watchfor from
[KP84]
Section 5.3.
Write a version of watchwho that stores the who output
as shell variables instead of files. Which version do you prefer?
Which version runs faster?
Example A.3. watchwhoM
#!/bin/bash
# watchwho: watch who logs in and out
PATH=/bin:/usr/bin
old= # create an empty var
while :
do
new=`who`
diff <(echo $old) <(echo $new) # at leat one net version
# of man diff has this idea
old=$new
sleep 10
done | awk '/>/ { $1 = "in: "; print }
/</ { $1 = "out: "; print }'