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.

188 lines
4.3 KiB

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