| The FreeBSD Diary | 
|  | (TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. | 
| 
periodic - using it to run shell scripts
9 November 1999
 | 
| This article documents how I used periodic to run a shell script every night. | 
| What is periodic? | 
| From the manual pages for periodic: The periodic program is intended to be called by cron(8) to execute shell scripts located in the specified directory. This program uses files located in the following directories: /etc/periodic/daily/ /etc/periodic/weekly/ /etc/periodic/monthly/ As indicated by the directory names, periodic is launched on a daily, weekly, and monthly basis. See man periodic for more details. | 
| The shell script | 
| I had recently installed a www interface to a mailing list
    archive and now I wanted to automagically update the files instead of manually running
    the batch job every day. The first step was to create a shell script which did what I wanted. Here is the contents of /etc/periodic/daily/470.hypermail-adsl: 
      Note that files within the periodic directories are executed in alphabetical order. This is why the file is prefixed with a number. For details on hypermail, please see hypermail - creating an www interface to a mailing list archive. | 
| GOTCHA! - Tuesday | 
| After testing the above script on Monday night to ensure it ran and did what I wanted,
    I left my box and went to bed, secure in the knowledge that the archives would be updated
    as I slept.   I was wrong.  The next morning the archives were untouched. 
    I had no idea why.  But checking the file permissions I think I found out why: -rw-r--r-- 1 root wheel 272 Nov 8 22:31 470.hypermail-adsl As you can see, the executable bit has not been turned on. Oh well, that's easy to fix: chmod 755 470.hypermail-adsl Now the file looks like this: -rwxr-xr-x 1 root wheel 272 Nov 8 22:31 470.hypermail-adsl Here's hoping that it runs properly tonight. | 
| GOTCHA! (part 2) - Wednesday | 
| It didn't run again.  Hmmm.  I asked on IRC for some clues.  They
    suggested path.  Of course!  I even remember it in the man pages.  I can't
    use plain old hypermail; I have to include the path.  Here is the newly
    amended script: 
      Now I'm not so sure about the changes I made earlier regarding the executable bit. But at least the files are now all of the same flag setting. Here's hoping for tonight! | 
| Finally | 
| The shell script ran last night.  I'm pleased.  Here's what I found in my
    "daily run output" mail message: 
      And this is what was at the bottom of the html page in question: 
      This script is working just fine. But I'll monitor it closely by examining using the daily run mail message. |