Bug 39941

Summary: /usr/sbin/periodic sends thousands of emails
Product: Base System Reporter: guolin <guolin>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
file.diff
none
file.diff none

Description guolin 2002-06-28 01:40:01 UTC
 The problems are:

1, /usr/sbin/periodic sends tons of email, when running hourly running scripts whether or not the latter generate outputs. Then email server will be overwhelmed if we have hundreds or thousands FreeBSD boxes.

2, periodic can not tell normal shell scripts from backup files ended with '~' and ',' , which are normally created by CVS/RVS/Perforce. it tries to run all executable files under base directory specified.

3, the coufiguration file */periodic.conf, which contain variable definition entries including <basedir>_{show|output|...}, will confuse Bourne Shell interpreter when the basedir contains character '.', which is normal for directory name but not appropriate for shell variable name substitution.

Fix: To fix the problem, we need to tell periodic
 1,  skip shell scripts ended with '~' and '.', 
 2,  substitute the '.' character to '_' in the periodic.conf and inform users about that special case, so that no base diretories like cron.daily and cron_daily exists at the same time. or if so, then the setting will overlaps.
 3, send emails only when necessary, normally that means scripts under base directory generating outputs.

The diff between original edited version of /usr/sbin/periodic  are attached.

shell> diff -c /usr/sbin/periodic /var/tmp/periodic
# Execute each executable file in the directory list.  If the x bit is not
  # set, assume the user didn't really want us to muck with it (it's a
***************
for arg
  do
      # Where's our output going ?
!     eval output=\$${arg##*/}_output
      case "$output" in
      /*) pipe="cat >>$output";;
      "") pipe=cat;;
--- 36,47 ----

  for arg
  do
+     # for special cases that the base directory has a '.' character contained,
+     # and difficult to change, then we can replace '.' with '_' in */period.conf,
+     # to pass the shell parameter name check for */periodic.conf
+     arg_in_conf=`echo $arg | tr '.' '_'`
      # Where's our output going ?
!     eval output=\$${arg_in_conf##*/}_output
      case "$output" in
      /*) pipe="cat >>$output";;
      "") pipe=cat;;
***************
How-To-Repeat:  just create a directory /etc/periodic/hourly, and create a simply output-nothing shell script hahaha.sh under it: 
    
   #! /bin/sh
   # do nothing and output nothing

   # echo "hahahaa... wrong :)"

 Set its executable mode bit and  run the periodic with hourly directory as its argument..

 sh -x /usr/sbin/periodic  hourly

 Then copy the hahaha.sh to hahaha.sh~ and run the same command above, you will find that both shell scripts are processed!

at last change the hourly directory name to cron.hourly name, and it will report problem even at beginning when processing the periodic.conf file!
Comment 1 Johan Karlsson freebsd_committer freebsd_triage 2002-06-28 02:55:48 UTC
State Changed
From-To: open->closed

Duplicate of PR 39940