, . - , , - . , - today. , UNIX cal. , . . , . ---------------------------------------------------- : at ---------------------------------------------------- at -  .   at hr:min cmd [;cmd ...]   at 12:00 echo "time for lunch!" . at 1 : 2 # @(#) tree v1.0 Execute command line at specific time Author: Russ Sage 2 4 if [ $# -lt 2 ] 5 then echo "at: wrong arg count" >&2 6 echo "usage: at hr:min cmd [;cmd ...]" >&2 7 exit 1 8 fi 10 ITS=$1; shift 12 while : 13 do 14 TIME=`date | cut -c12-16` 16 if [ "$ITS" = "$TIME" ] 17 then eval $@ 18 exit 0 19 else sleep 35 20 fi 21 done &   ITS , TIME  at? , . , . , , - - . at , . , . "" . , , .. Berkeley UNIX . System V. ? , UNIX, . , , - , at , , - , . at, , . at, , , at Berkeley, . , - at, at Berkeley shell. Berkeley , at - . (, shell, - .) at? at . , - , . : - , . :. ( 0 23 ), date. , date, at. , shell. , . , . at - UNIX - . at . - . at Berkeley , - . at . , . , at , . , , , - , , - . - . - while shell, . - , - . . - , , , - , . , : . at , , , - .  1. $ at 11:45 echo ^G^G It's almost lunch time (control-G) . 2. $ at 10:45 "if [ -s $MAIL ]; then echo ^G You have mail; fi" , - ($MAIL /usr/spool/mail/russ). , - , . 3. $ at 17:00 "c; date; banner ' time to' ' go home'" ( c, - ), - "time to go home" (" "). banner , - . - (, - c), .  at , . 4-8 . : . , - 2. 2, - . 2. shell ITS 10. ($1), :. - , . shift $1 . - $0 (.. at) ($@ $*). - , $0. at while 12-21. : (). - shell, , - , . true shell - . : true, - . : - shell. True, , bin ( , ls), , - . - . , . date 14. date - : ---------------------------- | | Mon Mar 31 06:54:25 PST 1986 | | , , . : 12-16. date, cut - . TIME. - , . - . 16-20. , , ( 16), (- 17), ( 18). , ( 19) . & 21 while . , shell ? . - , shell . shell , , , . shell - .  , at - , ? , shell . Bourne shell, control-D - . - nohup ("no hang up" - " "). Nohup , - . , - , . : nohup at 13:00 echo "back from lunch yet?" -shell, . , -shell . , . , , , 17 "eval $@". . - at "$@" . - " - ". , , . shell at. . at at 09:30 echo $HOME . $HOME, echo - /usr/russ. at 09:30 echo \$HOME echo $HOME $HOME. eval . , shell - , shell . , - .  , . at 0 23 . , .. 8:30 a.m. ( ) 8:30 p.m. ( ). " 10 - -". : at -n 10 echo "do in now plus 10 minutes" -n , 10 . at - , . , . , , , , - - , , , . , , - - . , - , , , . ------------------------------------------------------------- : b -------------------------------------------------------------- b   b any_command_with_options_and_arguments ( )   b cg f.c , cg - , 10. b 1 : 2 # @(#) b v1.0 Background task handler Author: Russ Sage 2 4 ($@; echo "^G\ndone\n${PS1}\c") &  b? , Bourne shell . &. , - ? shell, . , - , . - ps. shell, , , init, - shell ( shell, nohup). shell, nohup, shell. ps . - : while :;do date; done & ps shell (PID=32), - (PID=419) shell, while (PID=449). ----------------------- | | UID PID PPID C STIME TTY TIME COMMAND | | root 0 0 0 Dec 31 ? 0:03 swapper | root 1 0 0 Dec 31 ? 0:02 /etc/init | russ 32 1 0 14:18:36 03 1:26 -shV | russ 419 32 0 15:30:31 03 0:02 -shV | russ 449 419 2 15:30:31 03 0:02 -shV | ps, shell, init. "b ps -ef", b - , . , 471 shell, 1, init, shell (PID=32). ------------------------- | | UID PID PPID C STIME TTY TIME COMMAND | root 0 0 1 Dec 31 ? 0:04 swapper | root 1 0 0 Dec 31 ? 0:02 /etc/init | russ 32 1 1 14:18:36 03 1:30 -shV | russ 472 471 5 15:46:46 03 0:12 ps -ef | russ 471 1 0 15:46:46 03 0:00 -shV | ? , "" - . ? -, . - - - , , ps , . ps - , ps . - . - , shell - , , . - , , . , shell . , , - - . , ? , . b? b - , . . "done" -- shell. . - , , . , , PS1 . , UNIX . XENIX PS1 , - , shell, - shell . "sh" , . UNIX !  1. $ b ls -R .. , . , - - more, /dev/null. more , . , - , - . more , . 2. $ b echo hello > z z "hello", "done", z shell. b, . 3. $ b sleep 5; echo hello , b sleep. echo - . 4. $ b "sleep 5; echo hello" , b . - sleep , "5; echo hello" - sleep.  , 4 , &. - shell, - . shell, "done" . $@. : " , ". $@ (.. echo - ), shell . , ! , eval. , , " " - , , eval . , . , eval . , , - . b echo $HOME /usr/russ , - , , - . , - , (PS1). , shell - . --------------------------------------------------------- : greet --------------------------------------------------------- greet  - .   greet   greet greet, . greet 1 : 2 # @(#) greet v1.0 Timely greeting from the terminal Author: Russ Sage 2 4 if [ `expr \`date +%H\` \< 12` = "1" ] 5 then echo "\nGood morning.\nWhat is the best use of your time right now?" 6 elif [ `expr \`date +%H\` \< 18` ="1" ] 7 then echo "\nGood afternoon.\nRemember, only handle a piece of paper once!" 8 else echo "\nGood evening.\nPlan for tomorrow today." 9 fi  greet? - , - . - , . , . , shell-. - shell? , UNIX date, , . - . date . . , - , , ? . : , . : , . greet? Greet - , . . , , - - . , . , - . , , ( ) . Greet . - , - . greet .  1. $ if greet | fgrep 'morn' > /dev/null > then morning_routine > fi greet. greet - fgrep. "morn". , . fgrep ( ), morning_routine. 2. $ at 10:30 greet; at 13:50 greet .profile. at , - - . , . , , , .  if -then-else 4-9. - : if it is morning then echo morning statement "" else if it is noon then echo noon statement "" else echo evening statement "" , . 4 , 12 . , expr - ("1"). (`), , , 1 - , ([]). test , expr - . , 5 "- " . , expr. -, . , - . - test. expr , expr. shell. - , . date, - %H. expr , 12. , expr . 12, 0. , 1= 0=, , . , shell 1 , 0 - . , - if - . - , 0 "" then. , - 1 ( , 12) ( then), test. 1, test 0, . ! , - shell. - - . , . : , , . ( ), - . 4 "", 6. else if if. - shell . "else" "elif". if test , . 18, 6 . "", 8. else test, - , , 18:00. -------------------------------------------------------- : lastlog -------------------------------------------------------- lastlog  - .   lastlog [-l]   lastlog , lastlog 1 : 2 # @(#) lastlog v1.0 Report last login time Author: Russ Sage 2 4 if [ $# -gt 1 ] 5 then echo "lastlog: arg error" >&2 6 echo "usage: lastlog [-l]" >&2 7 exit 1 8 fi 10 if [ "$#" -eq "1" ] 11 then if [ "$1" = "-l" ] 12 then date >> $HOME/.lastlog 13 lastlog 14 else echo "lastlog: unrecognized option $1" >&2 15 echo "usage: lastlog [-l]" >&2 16 exit 1 17 fi 18 else echo "Time of last login : `tail -2 $HOME/.lastlog | 19 (read FIRST; echo $FIRST)`" 20 fi   FIRST HOME  lastlog? UNIX , - . . , , , - - . 9, - , - "" . , - ( , , ). . - . , . - . , , , . lastlog? Lastlog - , - . - $HOME/.lastlog. lastlog , - ls. "" , , - . lastlog - , .lastlog. .lastlog lastlog -l. .lastlog, lastlog - . , lastlog , .profile . .lastlog. .profile .  4-8 . lastlog , . - , lastlog 1. 10-20 if-then-else, , . 10 , , -l, . if 11 , - -l. , $HOME/.lastlog - lastlog . ( , .) -l, 14-16 - . , - else 18. , . - , , ? , - , - . .lastlog , - , . , - . . 18, . tail . , , - , 19. tail shell ( ), - . ? . tail "head -1". , . , . -------------------------------------------------------- : timelog -------------------------------------------------------- timelog  .   timelog   timelog , timelog 1 : 2 # @(#) timelog v1.0 Time accounting and statistics Author: Russ Sage 2 4 PROJ="" 6 while : 7 do 8 set `date` 9 echo " 11 $1, $2 $3 $4 13 Time Logger 14 ----------- Project: $PROJ 15 s) Select a project file 16 c) Create a new project file 17 l) List current project files 18 v) View the project file 19 n) Turn billing on 20 f) Turn billing off 21 r) Report ststistics 23 enter response (s,c,l,v,n,f,r,): \c" 25 read RSP 27 case $RSP in 28 "") break;; 29 s) echo "\Enter project name ( for exit): \c" 30 read PROJ2 31 if [ "$PROJ2" = "" ] 32 then continue 33 fi 34 if [ ! -s $PROJ2.time ] 35 then echo "you must specify a valid project file" 36 continue 37 fi 38 PROJ="$PROJ2";; 39 c) echo "\nEnter the new project name ( to exit): \c" 40 read PROJ2 41 if [ "PROJ2" = "" ] 42 then continue 43 fi 44 if [ -f "$PROJ2.time" ] 45 then echo "\n ** $PROJ2 already exists **" 46 continue 47 fi 48 PROJ="$PROJ2" 49 echo "\nProject file created: $PROJ" 50 echo "Project file created: `date`\nOFF: begin" > $PROJ.time;; 51 l) echo "\nCurrent project files:\n" 52 ls -l *.time 2>/dev/null || echo "no project files" | 53 sed "s/\.time//";; 54 v) if [ "$PROJ" = "" ] 55 then echo "you must select a project file first" 56 continue 57 fi 58 echo "\n:----------------------------" 59 more $PROJ.time 60 echo ":---------------------------";; 61 n) if [ "$PROJ" = "" ] 62 then echo "you must select a project file first" 63 continue 64 fi 65 if [ "`tail -1 $PROJ.time|cut -d: -f1`" != "OFF" ] 66 then echo "logging was not turned off" 67 continue 68 fi 69 echo "\nBilling turned on for project file: $PROJ" 70 echo "ON: `date`" >> $PROJ.time;; 71 f) if [ "$PROJ" = "" ] 72 then echo "you must select a project file first" 73 continue 74 fi 75 if [ "`tail -1 $PROJ.time|cut -d: -f1`" != "ON" ] 76 then echo "logging was not turned on" 77 continue 78 fi 79 echo "\nBilling turned off for project file: $PROJ" 80 echo "OFF: `date`" >> $PROJ.time;; 81 r) while : 82 do 83 echo " 84 Statistics 85 ---------- Project: $PROJ 86 a) Accumulative time totals 87 n) All times on 88 f) All times off 90 enter response (a,n,f,): \c" 92 read RSP 94 case $RSP in 95 "") break;; 96 a) awk '/Total:/ { PRINT $0 }' $PROJ.TIME;; 97 n) awk '/O