Monday, October 02, 2006

Using #crontab to schedule your tasks in linux

The situation: Before I go to my situation where i need to use the #crontab. Allow me to introduce you a bit about #crontab. crontab ( also known as cronjob) is a program to perform tasks (any tasks you give) during a specific time - even certain days of a week, or it could be anything. This command is just so powerful.

The problem: Ok say I want to move a folder /home/me/Desktop/videos to a new directory (or another network folder) and I don't want to do it right now (Maybe because I don't want my computer to slow down). So what do I do is set the move command (#mv) in the crontab file.

The Solution: Obviously the #crontab. Ok let's do it now.

1. Open the terminal. type the following command:

root@localhost:~#crontab -e

..where -e denotes edit. Next, the crontab file will be opened by using your default text editor (in my case vi). It should look like this:

# m h dom mon dow command

3. Edit the crontab. there are few parameters that you might want to take notes:

m = minutes
h = hour
dob = day of month
mon = month
dow = day of week
command = your unix command here.

4. Type in your cron job. I just take my previous example of moving the folder /home/me/Desktop/videos to the folder /home/me/MyCollections during 21 Sept 2006, 11AM on the fourth day of the week. So I edit my crontab and mine should looked like this:


# m h dom mon dow command

00 11 21 9 4 mv /home/me/Desktop/videos /home/me/MyCollections


or you may apply relative path:

# m h dom mon dow command

00 11 21 9 4 mv /home/me/Desktop/videos ../../MyCollections



Save and I can sleep up until noon and to see the folder are already moved =)

0 Comments:

Post a Comment

<< Home