Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.3 KiB

27 years ago
27 years ago
  1. #!/bin/sh -
  2. #
  3. # $OpenBSD: daily,v 1.28 1999/03/16 02:47:53 deraadt Exp $
  4. # From: @(#)daily 8.2 (Berkeley) 1/25/94
  5. #
  6. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
  7. host=`hostname -s`
  8. bak=/var/backups
  9. if [ -f /etc/daily.local ]; then
  10. echo ""
  11. echo "Running daily.local:"
  12. . /etc/daily.local
  13. fi
  14. TMP=`mktemp /tmp/_daily.XXXXXX` || exit 1
  15. trap 'rm -f $TMP' 0 1 15
  16. echo ""
  17. echo "Removing scratch and junk files:"
  18. if [ -d /tmp -a ! -h /tmp ]; then
  19. cd /tmp && {
  20. find -x . -name 'ssh-*' -prune -o -type f -atime +3 -execdir rm -f -- {} \;
  21. find -x . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \
  22. >/dev/null 2>&1; }
  23. fi
  24. if [ -d /var/tmp -a ! -h /var/tmp ]; then
  25. cd /var/tmp && {
  26. find -x . ! -name . ! -type d -atime +7 -execdir rm -f -- {} \;
  27. find -x . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \
  28. >/dev/null 2>&1; }
  29. fi
  30. # Additional junk directory cleanup would go like this:
  31. #if [ -d /scratch -a ! -h /scratch ]; then
  32. # cd /scratch && {
  33. # find . ! -name . -atime +1 -execdir rm -f -- {} \;
  34. # find . ! -name . -type d -mtime +1 -execdir rmdir -- {} \; \
  35. # >/dev/null 2>&1; }
  36. #fi
  37. if [ -d /var/preserve -a ! -h /var/preserve ]; then
  38. cd /var/preserve && {
  39. find . ! -name . -mtime +7 -execdir rm -f -- {} \; ; }
  40. fi
  41. if [ -d /var/rwho -a ! -h /var/rwho ] ; then
  42. cd /var/rwho && {
  43. find . ! -name . -mtime +7 -execdir rm -f -- {} \; ; }
  44. fi
  45. #find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
  46. # -o -fstype kernfs -o -fstype procfs \) -a -prune -o \
  47. # -name 'lost+found' -a -prune -o \
  48. # -name '*.core' -a -print -o \
  49. # \( -name '[#,]*' -o -name '.#*' -o -name a.out \
  50. # -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
  51. # -a -atime +3 -a -execdir rm -f -- {} \; -a -print > $TMP
  52. if egrep -q '\.core$' $TMP; then
  53. echo ""
  54. echo "Possible core dumps:"
  55. egrep '\.core$' $TMP
  56. fi
  57. if egrep -qv '\.core$' $TMP; then
  58. echo ""
  59. echo "Deleted files:"
  60. egrep -v '\.core$' $TMP
  61. fi
  62. if [ -d /var/msgs -a ! -L /var/msgs ]; then
  63. msgs -c
  64. fi
  65. if [ -s /etc/news.expire ]; then
  66. /etc/news.expire
  67. fi
  68. if [ -f /var/account/acct ]; then
  69. echo ""
  70. echo "Purging accounting records:"
  71. mv /var/account/acct.2 /var/account/acct.3
  72. mv /var/account/acct.1 /var/account/acct.2
  73. mv /var/account/acct.0 /var/account/acct.1
  74. cp /var/account/acct /var/account/acct.0
  75. sa -sq
  76. fi
  77. # If ROOTBACKUP is set to 1 in the environment, and
  78. # if filesystem named /altroot is type ffs, on /dev/* and mounted "xx",
  79. # use it as a backup root filesystem to be updated daily.
  80. [ "X$ROOTBACKUP" = X1 ] && {
  81. rootdev=`awk '$2 == "/" && $1 ~ /^\/dev\// && $3 == "ffs" && \
  82. $4 == "rw" \
  83. { print substr($1, 6) }' < /etc/fstab`
  84. rootbak=`awk '$2 == "/altroot" && $1 ~ /^\/dev\// && $3 == "ffs" && \
  85. $4 == "xx" \
  86. { print substr($1, 6) }' < /etc/fstab`
  87. [ X$rootdev != X -a X$rootbak != X ] && {
  88. sync
  89. echo ""
  90. echo "Backing up root filesystem:"
  91. echo "copying /dev/r$rootdev to /dev/r$rootbak"
  92. dd if=/dev/r$rootdev of=/dev/r$rootbak bs=16b seek=1 skip=1 \
  93. conv=noerror
  94. fsck -y /dev/r$rootbak
  95. }
  96. }
  97. echo ""
  98. if [ -d /var/yp/binding -a ! -d /var/yp/`domainname` -o "X$CALENDAR" = X0 ]
  99. then
  100. if [ "X$CALENDAR" = X0 ]; then
  101. echo "Not running calendar, (disabled)."
  102. else
  103. echo "Not running calendar, (yp client)."
  104. fi
  105. else
  106. echo "Running calendar in the background."
  107. calendar -a &
  108. fi
  109. # Rotation of mail log now handled automatically by cron and 'newsyslog'
  110. if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then
  111. echo ""
  112. echo "Cleaning up UUCP:"
  113. echo /etc/uuclean.daily | su daemon
  114. fi
  115. echo ""
  116. echo "Checking subsystem status:"
  117. echo ""
  118. echo "disks:"
  119. df -k
  120. echo ""
  121. dump W
  122. echo ""
  123. mailq > $TMP
  124. if ! grep -q "^Mail queue is empty$" $TMP; then
  125. echo ""
  126. echo "mail:"
  127. cat $TMP
  128. fi
  129. if [ -d /var/spool/uucp ]; then
  130. uustat -a > $TMP
  131. if [ -s $TMP ]; then
  132. echo ""
  133. echo "uucp:"
  134. cat $TMP
  135. fi
  136. fi
  137. echo ""
  138. echo "network:"
  139. netstat -i
  140. echo ""
  141. t=/var/rwho/*
  142. if [ "$t" != '/var/rwho/*' ]; then
  143. echo ""
  144. ruptime
  145. fi
  146. # If CHECKFILESYSTEMS is set to 1 in the environment, run fsck
  147. # with the no-write flag.
  148. [ "X$CHECKFILESYSTEMS" = X1 ] && {
  149. echo ""
  150. echo "Checking filesystems:"
  151. fsck -n | grep -v '^\*\* Phase'
  152. }
  153. if [ -f /etc/Distfile ]; then
  154. echo ""
  155. echo "Running rdist:"
  156. if [ -d /var/log/rdist ]; then
  157. logf=`date +%Y.%b.%e`
  158. rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
  159. else
  160. rdist -f /etc/Distfile
  161. fi
  162. fi
  163. sh /etc/security 2>&1 | mail -s "$host daily insecurity output" root