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 =)

Tips on creating SWAP partition

What is swap partition? : Save all of the technical explanation. If you are familiar with virtual memory in Windows, then SWAP does the same thing. If you are not, then SWAP partition is a partition where it becames the "secondary memory" apart from your physical memory (also commonly known as "RAM").

Say you have a piece of RAM with capacity 512MB. If your computer (running on Windows XP) uses memory more than 512MB (or eventually does), then your windows WILL NOT prompt out the message "Sorry, your are out of memory!!". Instead, windows will initialize a space of your hard disk (usually c:) drives to become "a memory" (that's why it is called virtual memory) to support the insufficient space in the physical RAM. This is the time where you will experience "slow moment" with your computer - tasks which takes 1 seconds to be completed with physical RAM may takes 3 1/4 months if it is on virtual memory!! (source:kingston.com).
p/s: so in case you running out of memory , buy a new RAM. Avoid virtual memory.

So as the SWAP partition. In Microsoft Windows, virtual memory is automatically set up by default (you may choose to change it manually in advanced properties). But in linux, you have to initialize the capacity of SWAP (virtual memory) by yourself - that's it by creating a special partition just for this virtual RAM purpose.

So how do I choose the size/capacity of the SWAP partition?
The general rules (and commonly applied nowadays) is to set up the value capacity of SWAP equals to double the size of the physical RAM. eg you have 256MB of physical RAM, then you need to initialize the size of swap to 512MB.

But since nowadays computers are advanced and may be powered by RAM which is much bigger than 512MB, say 1GB. If this is the case, you DO NOT have to initialize the size of SWAP up to 2GB!! It will be a waste of hard disk space. Since for general use, it is difficult for your RAM to even reach the consumption/resource allocation more than 1GB.

Saturday, September 30, 2006

Verify your download using md5sum

The situation: Often I found the md5sum term everytime I want to download softwares. At first I didn't even care what md5sum is. Ok, forget about it for a while...and talking of download, which there is one thing that annoys me regarding download and corrupted download file =.=

The Problem: How ? Eg I want to download ISO image for Knoppix Linux. After I download it, then (of course) without any question i will burn it. But it is only after burning and verifying the download, I realized it is a corrupted ISO file. There goes $1.00 of my CD-R.

The Solution: Up until now, I appreciate the md5sum, or MD5 checksum or MD hash . It is a command that can be used in terminal to verify download either it is the exact same copy (not corrupted) as in the mirror server... or it is already somehow corrupted during download process.

Open the terminal and navigate to the directory where the downloaded file is located. Type in the following command:

me@localhost:~#: md5um downloadedfile.tar.gz


...where downloadedfile.tar.gz is the file you've downloaded. Later the terminal will display the md5 hash number. verify whether it is the same as the one provided in download page. Good luck. =)