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.

173 lines
4.1 KiB

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