Saturday, August 15, 2009

Welcome to my blog!!!

Warm welcome to all linux newbies.. You will find a lot of interesting stuffs here which you can understand easily. Experienced guys please excuse..This is just a beginners guide....:)

Cron jobs tutorial for beginners

Cron is a utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs. Crontab (CRON TABle) is a file which contains the schedule of cron entries to be executed at specified times.

commands:

crontab filename Install filename as your crontab file.
crontab -e --> Edit your crontab file.
crontab -l --> Show your crontab file.
crontab -r --> Remove your crontab file.
crontab -v --> Display the last time you edited your crontab file

Inorder to setup a cron you just need to specify the task and the time at which it should be executed. Definitely it should be in the format as below. It can be a little tough at the beginning, but will be much easier if you learn how to specify the time at which a particular task should be executed. Workout with examples to get more idea about cron jobs.

Crontab syntax :-

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

ie,
minute hour day month day-of-week command-line-to-execute
0-59 0-23 1-31 1-12 0-7

In a linux server you can find cron entry for a user at /var/spool/cron/username


examples:

if you want a certain command to run at 5.30 am, you will have to code it as:
30 5 * * * command to execute

If you want something run at 8 pm everyday, it has to be coded as:
0 20 * * * command to execute (20 is 8 pm in the 24-hour time format)

If you want to set the cron job every sunday at midnight 11.30 PM
30 23 * * 0 command to execute (0--represents the Sunday)

If you want to run the task at 1am and 2am only from Monday to Friday:
* 1,2 * * 1-5 command to execute

If you want to execute a cronjob at 4 am every Sunday:
00 4 * * 0 command to execute

To execute a cronjob at 4:42 am every 1st of the month
42 4 1 * * command to execute

Cron also supports 'step' values.
A value of */2 in the date of month field means that the command runs every two days and */5 in the hours field would mean the command runs every 5 hours.

Difference between */5 * * * * and 5 * * * *

*/5 * * * * command to execute -->> This will execute the cronjob in every 5
minutes.

5 * * * * command to execute -->> This will execute cron job in 5th minute of every hour


If both the day of month and day of week are specified, the command will be executed when either of the events happen.
* 12 16 * 1 command to execute -->> command will be executed on every Monday and every 16th

Cron also accepts lists in the fields. Lists can be in the form, 1,2,3 (meaning 1 and 2 and 3) or 1-3 (also meaning 1 and 2 and 3)
59 11 * * 1,2,3,4,5 command to execute -->> will execute the command at 11:59 Monday, Tuesday, Wednesday, Thursday and Friday


to be continued...

ref:
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
http://en.wikipedia.org/wiki/Cron
http://www.aota.net/Script_Installation_Tips/cronhelp.php3
http://www.thesitewizard.com/general/set-cron-job.shtml
https://www.simplehelix.com/hosting/knowledgebase.php?action=displayarticle&catid=4&id=77

Monday, May 4, 2009

Linux Boot Process

There process of booting a linux system consists of various stages. The boot process is same in almost all the linux variants. I have tried my level best to explain it in a simple way, so that a beginner can understand the process easily.

Here we go...

When a system is switched on the processor looks at the end of system memory for the Basic Input/Output System or BIOS program and runs it. The BIOS is made up of two parts: the POST code and runtime services. POST(Power On Self Test) checks the system hardware and performs local device initialization. Then BIOS runtime services check for a valid boot device. If no configuration changes are made in BIOS it will first check floppy drive then harddisk drive and then on removable disk drives if any. If no boot device is found it will sends an interrupt and boot process will be terminated.

The boot device contains primary bootloader in the first 512-byte sector of the disk. This segment is called the Boot Sector. Sometimes it is also called Master Boot Record(MBR). Once a valid boot device is found, primary bootloader is loaded into RAM and BIOS passes control to it.

Stage 1

The primary boot loader that resides in the MBR is a 512-byte image containing both program code and a small partition table. The first 446 bytes are the primary boot loader, which contains both executable code and error message text. The next sixty-four bytes are the partition table, which contains a record for each of four partitions (sixteen bytes each). The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR.

The job of the primary boot loader is to find and load the secondary boot loader (stage 2) by looking through the partition table for an active partition. When it finds an active partition, it scans the remaining partitions in the table to ensure that they're all inactive. When this is verified, the active partition's boot record (secondary boot loader) is read from the device into RAM and executed.

Stage 2

The secondary boot loader is also called the kernel loader. The task at this stage is to load the Linux kernel and optional initial RAM disk.

The second stage boot loader has two functions:

1. Display the list of available kernels upon request, defined in bootloader configuration file.
(ie, for LILO /etc/lilo.conf and for Grub /etc/grub.conf)

2. Consult with filesystem to load the default kernel image and initrd image into memory.

With the images ready, the stage 2 boot loader passes the control to kernel image.

Stage 3

From here the Kernel stage begins.

The kernel image is a compressed image typically a zImage or bzImage.

The bzImage is decompressed by the C function decompress_kernel (located in ./arch/i386/boot/compressed/misc.c). When the kernel is decompressed into memory, it immediately initializes and configures memory paging and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices.

Then it loads the initial RAM disk(initrd) and loads all the necessary drivers. This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks. At this point, there are no user applications that allow meaningful input to the system, not much can be done with the system. To set up the user environment, the kernel executes the /sbin/init program.

Init

After the kernel is booted and initialized, the kernel starts the first user-space application. The /sbin/init program (also called init) coordinates the rest of the boot process and configures the environment for the user.


"I will not say I failed 1000 times, I will say that I discovered there are 1000 ways that can cause failure" -- Thomas Edison

ref:
http://www.ibm.com/developerworks/linux/library/l-linuxboot/
http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_reference_guide/s1-boot-init-shutdown-process.html