My company has Windows 2000 and Windows NT 4.0 servers in the headquarters office but typically only NT 4.0 servers in its many other offices worldwide. Occasionally, I need to schedule batch jobs (i.e., batch files) on remote servers in different time zones. Although the jobs don't need to run simultaneously, they need to run within a few minutes of one another.
I often use the Soon utility in the Microsoft Windows NT Server 4.0 Resource Kit to schedule jobs. However, in this case, the Soon utility doesn't work because it doesn't take time zones into account. Thus, I wrote the script RmtSoon.pl, which lets me schedule jobs on remote servers in different time zones.
The key to RmtSoon.pl is Win2K's Net Time command. Using this command, you can obtain a remote machine's time in respect to your time zone (referred to as the current time) and in respect to the time zone for which the remote machine was configured (referred to as the local time). NT's Net Time command doesn't offer this functionality (the command is new to Win2K), so you must execute RmtSoon.pl on a Win2K machine. However, the remote machine can be either Win2K or NT. As RmtSoon.pl illustrates, in a mixed environment, you can use Win2K scripting to solve NT problems.
When you execute RmtSoon.pl, you need to pass three parameters to it. On the command line, type
perl rmtsoon.pl serverName timeOffset batchJob
where batchJob is the batch file you want to execute, timeOffset is how many minutes until that batch file executes (this number can range from 1 to 59), and serverName is the name of the remote server on which to run the batch file. If you want to run RmtSoon.pl in test mode (i.e., the script doesn't schedule the job), you append -t to the end of the command.
After RmtSoon.pl obtains the three parameters, it uses the Ping command to verify that the specified remote server is available. If the server is available, the script uses the Net Time command to obtain the remote server's local time, as the excerpt of code in Listing 3 shows. RmtSoon.pl then adds the specified offset time to the local time and passes the result to the At command to schedule the job on the remote machine.
You can find the entire RmtSoon.pl script in the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com). You execute RmtSoon.pl for each remote server on which you want to run the batch file.