Alternative To Cron – Windows Scheduler

Tuesday, January 8th, 2008

I run a bunch of servers for my business. One server, in particular, is better and more advanced than the others. Well, the server isn’t more advanced, the software installed on it is. On that server, I am running Plesk, which I have learned is fantastic.

I recently began automating many of my more boring tasks by using cron jobs. A “cron is driven by a crontab, a configuration file that specifies shell commands to run periodically on a given schedule.” Basically, if you have an application that needs to run on a schedule and is capable of being triggered by a cron job, using this feature can be a real time saver.

One of the reasons I didn’t start using this nice little feature sooner is because I had no idea how to set it up through SSH. When I got the new server with Plesk installed on it, setup became very easy. I Just used the “Scheduled Task” feature and it was all done.

Well, that’s all fine and dandy for the capable applications on the server running Plesk, but what about the other servers not running Plesk? I would still have to setup the cronjobs using SSH. Believe it or not, I have been avoiding setting up those jobs to this day. Just a bit of background…these jobs only need to run every few days or so. What I am about to suggest is not really suitable for jobs that need to run every few minutes.

Last night, I started fooling around with “Windows Scheduler.” The link I just gave you is for XP…the information I am going to give you below is for Vista. I am sure you will get the gist. Windows Scheduler is a great feature similar to cron that is installed on your own computer, not the server where your website is being hosted, but does something very similar. It automates those boring tasks that you and I would forget about very easily.

So, how do you run a cronjob with Windows Scheduler? If your cron enabled application has a file that needs to be visited (usually something like cron.php, or something along those lines), it’s quite simple. All you need to do is tell your personal computer to wake up, open a browser and visit that page. Here is how you do it:

The first thing you want to do is to open your control panel and click on “System and Maintenance.”

control-panel.gif

Then, on the next page, click “Scheduled Tasks.”

scheduled-tasks.gif

After you click that, you will be brought to the Task Scheduler screen. It’s a new window. I am going to go over how I set up a new task this morning. As I said above, all I wanted to do was to have a browser window open and automatically have it visit a particular URL.

The first thing I did was to click on the “Task Scheduler Library” and then on “Create Basic Task.” The Task Scheduler Library is where I am going to store these tasks.

task-scheduler.gif

After you click “Create Basic Task,” a window will open with space for you to describe your new task.

create-task.gif

Fill in the information so it’s recognizable to you. Then, click next (down at the bottom). The next window is going to ask you when you want your task to run.

when.gif

I set it to “Daily.” On the next screen, you can adjust it.

On this screen, you can describe more about your daily task, such as start date, time and frequency. I set mine to every other day (a 2 in the recur every: box).

describe-daily.gif

This screen asks you what action you want to perform. As I said above, I wanted to open a browser, so I click the “Start a Program” button.

action.gif

Here’s is the trickiest part. On the next screen, you have to choose which program and what additional arguments.

start-program.gif

In the “Program/script” box, I browsed to open Firefox, which in this case gave me this path, “C:\Program Files\Mozilla Firefox\firefox.exe.” In the “Add Arguments” box, I put the URL of my cron file, such as “http://www.mywebsite.com/cron.php.”

In the final screen, you are offered a summary of what you filled in. I like the check off the “Open properties” box for some extra steps I needed to take. Click “Finish.”

final.gif

The last few items are quite simple, so I won’t offer screen shots for them. When the Properties box opens up, click the “Conditions” tab up top. Since my computer goes into sleep mode after a half hour of non use, I want to wake it up to preform the task, so I click the “Wake computer” check box. Then, I click the “Settings” tab up top. In case the task is missed for some reason, I click the “Run task as soon as possible…” check box and the “If the task fails, restart every:” check box. You can put your own values in there.

When you are finished, hit “OK” and see how it goes. I tried this with a specific time when the computer was in use and it had no problems. I haven’t tried it when the computer was in sleep mode, so we’ll see what happens. Give it a shot and let me know your results.

Related posts

Setting Up a Cron Job in Plesk – Part 2

Monday, December 17th, 2007

My cron jobs have been running as scheduled, but the strange part is I have been getting status emails…with errors in them.

I am using the cron jobs (Scheduled Tasks) in Plesk to run my sitemap generators. Every time the generator runs, it deletes the old generated files and creates new ones. I was wondering why I was getting errors. Sometimes, the files wouldn’t generate at all.

I called tech support at my new wonderful hosting company. Melissa explained to me that I set up the cron jobs under the user account for that domain. When the jobs are run via web interface online, they are running under the apache user. When they are run by cron, they are running under a different username, without the same privileges. The cron run is not able to delete those existing files and write new ones.

The way I got around this in Plesk was to click on “Server” (over in the left column) and then “Scheduled Tasks.” Once in the scheduled tasks manager, I clicked on “Apache” to set up the scheduled tasks under that user.

I am running the sitemap right now through the cron job…wait…it just finished with no errors and the files were updated correctly. I did not receive a status email because I set the email address up while the cron job was running. I am running a different site right now and will let you know how it goes.

By the way, Plesk is very good.

Related posts

Setting Up a Cron Job in Plesk

Thursday, December 13th, 2007

I have been putting this off for a while. For some time, I have had the need to set up a cron job to run my website sitemap generators. Currently, I do them by hand. Every few days, I log in to each one and run the generator. This gets a little tedious, because I have to do about thirty of them.

I have always known there is a function in the sitemap generators that allows a cron job to kick the generators on. All I had to do was set it up. Now, I am not all that good with that little black screen…SSH. I mean, I use PuTTY for some things, but not all that much. I would rather use a nice GUI to take care of these tasks.

Well, it just so happens that Plesk offers that GUI. By the way, I am talking about Plesk 8.1 here.

Ok, the first thing I did was to login to Plesk. Then, I clicked on, “Domains.” I clicked the domain I was interested in setting up a cron job for. Next, I clicked the “Scheduled Tasks” icon and then the system user. Once I was done clicking all that stuff, I clicked the “Schedule a Task For …” That’s the easy part. Well, the rest is easy too, but at least I was at the place I had to be to set up the job.

Once I was at the task page, there were a few things I had to fill in to set up the job. First, I checked off “enabled.” I think that’s pretty self explanatory.

Basically, I wanted this php script to run every two days at 4AM. It’s pretty simple. For the first field, labeled, “Minute,” I put in a “0.” That will start at zero minutes of the hour. For the “Hour” field, I put in a “4.” This will start the script at the fourth hour of the day. It is based on the 24 hour clock. Ignore the periods after the digits. I put them in there just for grammar’s sake. For the “Day of the Month” field, I put in an “*.” I guess that means any day. I also put in an “*” for the “Month” field. For the “Day of the Week” field, I put in a “*/2.” This means that the script will be initiated every two days. For the last field, “Command,” I put in the path to the cron file in the script. That is something you will need to get from the script itself.

This was the first time I did this. If there is anything I missed, anything I did wrong or anything that might have been done more efficiently, please let me know by way of comment.

Related posts




Free Online Ads
Motorcycle Classifieds
Boats For Sale
Free Auto Ads
Free Pet Classifieds
Free Classifieds