fork download
  1. #! /bin/sh
  2.  
  3. # NAME
  4. #
  5. # remind -- print reminders of upcoming events
  6. #
  7. # USAGE
  8. #
  9. # remind -- show reminders for next seven days
  10. # remind [year] month day message -- add reminder to database
  11. #
  12. # DESCRIPTION
  13. #
  14. # Remind maintains a database of reminders in the .reminders file,
  15. # in the user's home directory, each a single line of the form
  16. #
  17. # [year] month day message
  18. #
  19. # Year is optional, and must be an integer greater than 99; if no
  20. # year is given, the reminder applies to all years (for instance,
  21. # birthdays).
  22. #
  23. # If remind is called with no arguments, it writes to standard
  24. # output all reminders that occur within the next seven days. If
  25. # remind is called with arguments giving a date and message, a
  26. # reminder is added to the database. Any time remind is called,
  27. # all past reminders are deleted from the database.
  28. #
  29. # EXAMPLE
  30. #
  31. # $ date
  32. # Sun Jun 30 19:45:38 CDT 2019
  33. # $ remind 4 2 Anne birthday
  34. # $ remind 10 13 Kate birthday
  35. # $ remind 7 4 Independence Day
  36. # $ remind 2019 7 2 lunch with Pat
  37. # $ remind 2019 5 13 dentist 2:00pm
  38. # $ remind
  39. # 7 4 Independence Day
  40. # 2019 7 2 lunch with Pat
  41. # $ cat ./reminders
  42. # 4 2 Anne birthday
  43. # 10 13 Kate birthday
  44. # 7 4 Independence Day
  45. # 2019 7 2 lunch with Pat
  46. #
  47. # INSTALLATION
  48. #
  49. # Copy this file to /usr/local/bin/remind, then chmod +x.
  50.  
  51. REMINDERFILE=/home/$(whoami)/.reminders
  52. TEMPFILE=$(mktemp)
  53.  
  54. if [ $# -gt 0 ]
  55. then PRINTING=0; echo "$*" >> $REMINDERFILE
  56. else PRINTING=1
  57. fi
  58.  
  59. gawk '
  60.  
  61. # _The_Awk_Programming_Language_ by Aho, Kernighan and Weinberger
  62. # daynum function from solution to Exercise 3.8
  63. # only valid from 1901 to 2099; performs no validation
  64. function daynum(y, m, d, days, i, n) { # 1 == Jan 1, 1901
  65. split("31 28 31 30 31 30 31 31 30 31 30 31", days)
  66. # 365 days per year, plus one for each leap year
  67. n = (y-1901) * 365 + int((y-1901)/4)
  68. if (y % 4 == 0) days[2]++ # leap year from 1901 to 2099
  69. for (i = 1; i < m; i++) n += days[i]
  70. return n + d }
  71.  
  72. BEGIN {
  73. tempfile = "'$TEMPFILE'"
  74. printing = '$PRINTING'
  75. "date +%Y%m%d" | getline datestring
  76. year = substr(datestring,1,4)
  77. today = daynum(year,
  78. substr(datestring,5,2)+0,
  79. substr(datestring,7,2)+0) }
  80.  
  81. $1 < 100 || ($1 >= 100 && daynum($1, $2, $3) >= today) {
  82. print $0 >> "'$TEMPFILE'" }
  83.  
  84. printing && $1 < 100 &&
  85. today <= daynum(year, $1, $2) &&
  86. daynum(year, $1, $2) <= today + 7
  87.  
  88. printing && $1 >= 100 &&
  89. today <= daynum($1, $2, $3) &&
  90. daynum($1, $2, $3) <= today + 7
  91.  
  92. ' $REMINDERFILE
  93.  
  94. mv $TEMPFILE $REMINDERFILE
  95.  
  96. # PLB 6/30/2019
Runtime error #stdin #stdout #stderr 0s 23336KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
whoami: cannot find name for user ID 20083
gawk: cmd. line:19: fatal: cannot open file `/home//.reminders' for reading (No such file or directory)
mv: cannot create regular file '/home//.reminders': Permission denied