# # executeInterval.ps1 # # Start a program every couple of days. # Reads program name and interval from configuration file # # Author: Bernd Schandl, schandl@gmx.com # License: GPL v2 # THE PROBLEM I am using the rsyncbackup script of the German magazine c't for all my backup needs (http://www.heise.de/software/download/rsyncbackup.vbs/39087). First, I had the script in my autostart folder which worked ok; but it just made too many backups, because I had a new version whenever I logged off and on again. I tried to use the Windows task scheduler to make one backup per week but got an error message I did not understand. Also, some other programs downloaded from the web did not do what I wanted (eg. they did not perform a backup when I did not log on the configured day of the week but waited for the next week). So I programmed my own small script. THE SOLUTION The script executeInterval is programmed with Microsoft Powershell. It reads the name of the program to execute and an interval (in days) from a configuration file (executeInterval.cfg). It executes the program when the last time it was run is equal or more than the configured number of days ago. The date of last execution is written to a run file (executeInterval.run). All actions are written to a log file (executeInterval.log). The format of the configuration file is easy: First line is the program to execute, second line is the number of days. A sample file is included. The interval 0 is used because it is best for testing purposes. Change it as soon as you have your setup running. My autostart entry looks as follows: - Program is: Path\to\powershell.exe Path\to\executeInterval.ps1 - Working directory is: Path\to\executeInterval The script requires a working Powershell installation. I am using it with Powershell 2.0 and Windows Vista SP2 but I am sure that it runs with other Powershell and Windows versions. THE LIMITATIONS This is my first Powershell script. It has a number of limitations: - The script has to be in the same directory as the program to execute in order to have the correct working directory for the other program. - The script has to have write access to the directory where it is located. - All files (ps1, cfg, run, log) have to in the same directory. - Only one external program can be controlled. - The interval can only be given in "number of days". - Configuration file as simple text file instead of XML with the possibility of commenting. - Error handling is very limited. THE REQUEST Help me! I would be very thankful if you provided any help on improving the code and/or overcome the limitations; new ideas are of course welcome as well. Feedback including code snippets are preferred of course.