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.

183 lines
4.2 KiB

28 years ago
  1. #!/bin/sh -
  2. #
  3. # $OpenBSD: daily,v 1.17 1997/01/17 06:18:19 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 . -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,sync
  93. fsck -y /dev/r$rootbak
  94. }
  95. }
  96. echo ""
  97. if [ -d /var/yp/binding -a ! -d /var/yp/`domainname` ]; then
  98. echo "Not running calendar, (yp client)."
  99. else
  100. echo "Running calendar."
  101. calendar -a
  102. fi
  103. # Rotation of mail log now handled automatically by cron and 'newsyslog'
  104. if [ -d /var/spool/uucp -a -f /etc/uuclean.daily ]; then
  105. echo ""
  106. echo "Cleaning up UUCP:"
  107. echo /etc/uuclean.daily | su daemon
  108. fi
  109. echo ""
  110. echo "Checking subsystem status:"
  111. echo ""
  112. echo "disks:"
  113. df -k
  114. echo ""
  115. dump W
  116. echo ""
  117. mailq > $TMP
  118. if ! grep -q "^Mail queue is empty$" $TMP; then
  119. echo ""
  120. echo "mail:"
  121. cat $TMP
  122. fi
  123. if [ -d /var/spool/uucp ]; then
  124. uustat -a > $TMP
  125. if [ -s $TMP ]; then
  126. echo ""
  127. echo "uucp:"
  128. cat $TMP
  129. fi
  130. fi
  131. echo ""
  132. echo "network:"
  133. netstat -i
  134. echo ""
  135. t=/var/rwho/*
  136. if [ "$t" != '/var/rwho/*' ]; then
  137. echo ""
  138. ruptime
  139. fi
  140. # If CHECKFILESYSTEMS is set to 1 in the environment, run fsck
  141. # with the no-write flag.
  142. [ "X$CHECKFILESYSTEMS" = X1 ] && {
  143. echo ""
  144. echo "Checking filesystems:"
  145. fsck -n | grep -v '^\*\* Phase'
  146. }
  147. if [ -f /etc/Distfile ]; then
  148. echo ""
  149. echo "Running rdist:"
  150. if [ -d /var/log/rdist ]; then
  151. logf=`date | awk '{printf "%s.%s.%s", $6, $2, $3}'`
  152. rdist -f /etc/Distfile 2>&1 | tee /var/log/rdist/$logf
  153. else
  154. rdist -f /etc/Distfile
  155. fi
  156. fi
  157. sh /etc/security 2>&1 | mail -s "$host daily insecurity output" root