It was late at night when the Young Mage was walking through the Tower. Wandering aimlessly, he stared at the looming walls, spiraling staircases, and catwalks when, all of the sudden, he heard a buzzing from above.
Tumbling through the air, it looked like a small robot was making it’s way down toward the Mage. The little gizmo finally made it to the mage and bobbed up and down about a foot above his head.
“Hello!” the robot said.
“Um.. Hi” the Mage replied.
“Nice night, isn’t it?”
“Sure, I suppose. Um.. who are you?” the Mage asked.
“I’m a daemon. My name is Crond” the robot replied.
“Oh, a daemon! I learned about daemons! You guys work in the Tower and do various jobs.”
“That’s right!” Crond said.
“And just what job do you do, Crond?” the Mage asked.
“I make sure things get done at a specific time.”
“Oh, how’s that work?”
“Well, Mages, like yourself, tell me they need something done at a certain time, and I do it.” Crond explained.
“I see. So a Mage just walks up to you and says they need something done and that’s it?” the Mage asked.
“Well, they need to fill out a form.”
“Yep, a crontab form. After they fill it out, they’re all set.”
“Well what does the form look like?”
“It looks a little something like this:”
minute hour day month weekday job
minute = minute (0-59) hour = hour (0-23) day = day of the month (1-31) month = month (1-12) weekday = day of the week (0-7 where 0 and 7 are both sunday. or use names like mon,tue,wed) job = job -- the path to the script or program you want to run
“See?” Crond explained, “They just fill in the sections and that’s it. So for instance, if a Mage wanted me to start his laundry every Sunday at 9 AM, the form would look like this:”
0 9 * * 7 /usr/local/bin/laundry.sh
“What do the stars and zeros mean?” the Mage asked.
“That star is the same as the wildcard star — it means anything. So the stars in the laundry form mean ‘Every day of the month and every month of the year’. Since the Mage then specified Sunday, I’ll only run it on Sundays — but if he didn’t I’d start his laundry every day all year long at 9 AM. The zero just means to start it at 9 AM exactly — not 9:01 or 9:43.”
“I see,” the Mage said. “So if I needed to be woke up at 6:00 AM every day, I would fill out a from like this:”
0 6 * * * /usr/local/bin/alarm-clock.sh
“Yep,” Crond replied, “but I’m sure you want to sleep in on the weekends, so you can tell me that you want woke up only on weekdays like so:”
0 6 * * 1-5 /usr/local/bin/alarm-clock.sh
“The 1-5 means Monday through Friday.” Crond said.
“OK, but sometimes I hit the snooze button too. Can you do that?” the Mage asked.
“Sure can, just like this:”
0,5,10 6 * * 1-5 /usr/local/bin/alarm-clock.sh
“Then I’ll set your alarm off every 5 minutes up until 6:15 AM.” Crond said.
“OK, and if I wanted to snooze the whole hour, would it be:”
0,5,10,15,20,25,30,35,40,45,50,55 6 * * 1-5 /usr/local/bin/alarm-clock.sh
“Yes,” Crond said, “that’ll work, but it’s easier to just do this:”
*/5 6 * * 1-5 /usr/local/bin/alarm-clock.sh
“OK, I get it.” the Mage replied. “You’re a pretty useful daemon! How can I ever get a hold of you if I need to fill a form out?”
“Just cast this spell:”
“That will bring up a text-editor and you can just fill out the form on the next empty line. It’s as easy as that!” Crond said.
“Sounds like it!” said the Mage. “By the way, what are you doing flying around the Tower anyways?”
Crond handed the Mage a crontab form that contained:
0 22 * * 1-5 /usr/local/bin/curfew.sh
“Oh, well I better be getting back then,” the Mage said, “Thanks again for all your help!”
“No problem!” Crond replied, “Those are just the basics of me. If you want to learn more, cast the following spell:”
man 5 crontab
And with that, the gears on Crond wound up faster and off he flew.