|
Grex > Test > #34: Automatically setting my perms depending on the hour and day | |
|
| Author |
Message |
popcorn
|
|
Automatically setting my perms depending on the hour and day
|
Oct 6 07:09 UTC 1991 |
This item has been erased.
|
| 4 responses total. |
remmers
|
|
response 1 of 4:
|
Oct 6 13:12 UTC 1991 |
The C shell itself can do numeric comparison, Boolean operations,
and if-else control flow, so I think you can avoid awk. How about
something like this?
set date = `date '+ %w %H'`
if ($date[1] == 0 || $date[1] == 6 || ($date[2] > 5 && $date[2] < 22)) then
mesg y
else
mesg n
endif
|
mdw
|
|
response 2 of 4:
|
Oct 6 13:43 UTC 1991 |
You definitely want to get rid of the "temp.mesg" file, and not using
awk is another win. Even with awk, it's a bit silly to pass it strings
like "Day of Week", since awk doesn't really understand English. John's
example is much better on all these counts. As it happens, the c shell
can also do alphabetical comparisons, so it should be a somewhat
straight-forward extension to extend John's example to handling
Valerie's "known bugs".
This could also be done with the Bourne shell, albeit not quite as
cleanly. The trick there would be to use the "case" statement, which
doesn't involve forking another program (unlike '['--an alias for 'test'
on many systems), yet is capable of doing fairly complex pattern
matching.
|
mju
|
|
response 3 of 4:
|
Oct 6 20:42 UTC 1991 |
(Most modern Bourne shells -- by "modern", I mean most SysV versions, and
perhaps 4.3BSD as well -- have "test" and "[" implimented as builtins,
so you don't have the overhead of forking a /bin/test. Still, Marcus's
point is well taken; you definitely want to avoid forking a new process
whenever you can. In this case, it might be faster to write a C program
to do a time() followed by a localtime() to figure out what time it is,
and then print "mesg y" or "mesg n" depending on what behavior is
appropriate.)
|
popcorn
|
|
response 4 of 4:
|
Oct 6 20:52 UTC 1991 |
This response has been erased.
|