Friday, December 17, 2010

Cron Scheduling in Linux


This is the blog I m going to write to my followers who are a bit lazy.................

Suppose you have a server with you and you have to make the backup frequently on the same machine or some other on the network ..think how to monotonous job this is ????

Don't worry solution is here...you can schedule your system to make the backup of your data according to the time you mention.....this is cron scheduling

For doing so you have to change your crontab file in the directory /etc

You are to do as follow.....
1. Open your terminal
2. and type the command login as root user
3. check for the file 'etc/cron.allow' & '/etc/cron.deny' in case of some system it may be 'etc/cro.d/cron.allow' & '/etc/cron.d/cron.deny'

cron.allow contains the names of the user allowed to schedule the cron jobs and ..
cron.deny contains the names of the user which are not allowed to schedule the cron jobs
If none of the file exist then the root is the only user which can schedule the jobs

4. If you want to add some user to schedule the cron jobs then add the name of that user in the cron.allow file same for denying the user add them in the cron.deny file by using the following command it depends on you which editor you use (as my favorite editor is 'vim')..

~/# vi /etc/cron.allow

and simply add the list of user you want to allow one user in a line

5. After this you can schedule the job by using the one of the user in the cron.allow file or which are not in allow.deny (but I will show you below by root user).

6. Now write the command as below to schedule the cron jobs...
~/# vi /etc/crontab (You may use your favorite editor )

You will see on screen as in image....



In the above figure the commented part is not of over interest....the part of interest is from the line 'SHELL=/bin/sh'
It specify the default shell
The line next to it is to set the default variable 'PATH'

Now most important part of over requirement starts

Here commented line work as the heading for each element in the next line which have the specfic meaning as...

m for minute between 0 and 59
h for hour between 0 and 11
dom for day of month between 1 and 31
mon for month between 1 and 12
dow for day of week between 0 and 7, sunday is represented by 0 or 7, monday by 1, etc ...
user the command is to be run as a user
command to execute the command

for specifying the time we replace the corresponding '*'with the required digit

for example

we want to schedule our system to copy the file named index.php from dir /var/www/index.php to /home every hour
then add a line to crontab as..

0 * * * * root cp /var/www/index.php /home

for daily at 0800hr write as

* 08 * * *

if you want to run the command every minute the write as

* * * * *

apart from it there are some special character also

- for specifying the range
, for specifying the different values
/ for specifying the rate

examples

* * 1-15 * * it runs the command first fifteen days of months

10,12,13 * * * * it runs the command at 10th,12th and 13th minute of each hour

*/5 * * * * it runs the command every five minute

Instead of five stars you may use string to save your time which have the similar meaning to stars as below..

String Action
@reboot execution at boot
@yearly execution once a year, "0 0 1 1 *"
@annually execution once a year, "0 0 1 1 *"
@monthly execution onnce a month, "0 0 1 * *"
@weekly execution once a week, "0 0 * * 0"
@daily execution once a day, "0 0 * * *"
@midnight execution once a day, "0 0 * * *"
@hourly execution once an hour, "0 * * * *"

all the cron send the mail to you account about the output details of the command execution so to stop the mail append the following behind you cron command '>/dev/null 2>&1'

example:
0 * * * * root cp /var/www/index.php /home >/dev/null 2>&1

To send the email to some other user for example sachinnain0@nixcraft.in do as below

MAILTO=sachinnain0@nixcraft.in
0 * * * * root cp /var/www/index.php /home >/dev/null 2>&1

7. Now save you file and restart the cron by using the command

~/# /etc/init.d/crond/restart

there are some useful command for cron as


~/#crontab -e to edit the crontab file as we did above using the vim editor

~/#crontab -l list all your crontab jobs
~/#crontab -u username -l to list the all jobs for specified user
~/#crontab -r to remove all the cron jobs
~/#crontab -r -u username to remove all the cron jobs for specified users


This is all about the cron scheduling so use it to avoid the boredom as well as time waste.......





Saturday, September 25, 2010

File Permissions in Linux

Some time you may have seen that you are not able to access some of the file or directory of your own system. Do you know why ..?

No?

Your answer is here....
As you know, Linux is a multiuser OS. So every user have the permissions for a particular dir or file. A user not given authentication will not be able to access that...

Before going to the permission manipulation a would like to tell you some basics of it.

There are three types of ownership in Linux as..

User:
It is the creator of the file. It is assigned by default to the creator.

Group:
It is the bunch of the user belongs to the group to which file belong. All the user of that group have the access permission to that file

Other:
The user which neither owner of the file nor belongs to the group of the file are under the category of other or in other words we can say that we are making the folder global.

Other than all these, each file have three types of permissions for all types of user separately as follow....

Read:
A user provided read permission will be able to read the file only he is not able to read it.

Write:
This permission to the user provide the access the file for making the changes to the file.

Exicute:

This is the permission given to particular user for executing the program file or shell script.


Now after knowing all this basics next question generally comes to everybody's mind (As it came to mine even) how to know that which user is being provided with what permissions, who is owner of file and which group it belongs whether it is a file or a directory.......

Use the following 'ls' command in listing mode (by using -l with command) as

sachin@ubuntu:~$ ls -l

and it will result as..

total 37576
-rw-r--r-- 1 sachin sachin 4949 2005-08-22 22:10 class.mysql.php
-rw-r--r-- 1 sachin sachin 8174 2005-10-08 03:31 class.table.php
drwxr-xr-x 5 sachin sachin 4096 2010-09-25 22:55 Desktop
drwxr-xr-x 3 sachin sachin 4096 2010-08-20 17:05 Documents
drwxr-xr-x 2 sachin sachin 4096 2010-09-23 12:45 Downloads
-rw-r--r-- 1 sachin sachin 179 2010-05-09 01:21 examples.desktop



where each column have the significant meaning....




In the file permission column you see something like dxw-rw---x-

In which each letter have significant meaning..

The first character can be any of these

'-'-- regular file
'd'-- directory
'l'-- symbolic link
's'-- unix domain socket
'p'-- Named pipe
'c'-- Character device file
'b'-- Block device file

the next nine character represent the owner (next three) group (next three) other (next three)
these may contain only following four character as(In all group of three in all user three character represent read, write and execute respectively )

'-'-- No permission
'r'-- Read permission
'w'-- write permission
'x'-- Execute permission

Now I explain the file in the above image...
1. It is a directory
2. Owner of the file is 'sachin' and group is also sachin
3. Owner have the all three permissions read, write and execute
4. All the user of 'sachin' have the read and execute permission.
5. Where as other user also have the read and execute permission


Now the question is.... How to set or change the permission of the user and groups

There are two ways to do so one is symbolic mode and other is numeric mode.
First we will discuss the symbolic mode

Example:

$chmod u-x Desktop

the above command will remove the execute permission of owner

It has three parts as
Which user ? 'u' for owner, 'g' for group and 'o' for others

what ? '+' add the permission,'-' remove the permisson, '=' exactly gives the assigned permission

$chmod g=rx Desktop

the above command will assign the read and execute permission to Desktop no any other permission


Secondly we will do the same using numeric mathod...

$chmod 777 Desktop

the above command give all the permission to all user

In above command first number represent the owner second group and last represent the other

and the number have the following meaning

0 No permission
1 execute permission
2 write permission
4 read permission
1+2=3 execute and write permission
1+4=5 execute and read permission
2+4=6 write and read permission
1+2+4=7
All the three execute, write and read permission


Now, In the last one thing is left....
how to change the owner and group of file or dir

Use the following command

$chown ownername fileordirname


the above command will change the owner of the fileordirname to ownername

and

$chgrp groupname fileordirname

the above command will change the group of fileordirname to groupname....


Note: If you use -v(vebose ) will show you what it has done with the file or dir and -R(to be used with dir only) will apply the changes recursively to all the files and dir contained in the given dir.

Sunday, August 29, 2010

Linux Directory Structure

Linux is a open source so every body has the freedom to put their source codes where he/she wants(Just like a person who want to decorate his home he is free to put things where he likes it). There are no boundation regarding it but if you want to distribute it then it may create the confusion to others because there are so many vendors of Linux (Suppose you are made to enter somebody's home and asked to find something from there then think of that situation. You will be total balnk).

So to avoid this confusion a International FSSTND ( File System Standard ) was made. So that user and developer should not get confused and to save the time in searching the things.

I am going to explain the Linux Dir. Structure based on FSSTND....

/
|---root
|---home
|          |----ftp
|          |----httpd
|          |----samba
|          |----user1
|          |----user2
|---bin
|---sbin
|---proc
|          |
|          |----1
|
|---usr
|          |
|          |----bin
|          |----sbin
|          |
|          |----include
|          |
|          |----lib
|          |----local
|          |----man
|          |----info
|          |----doc
|          |----tmp
|          |----X11R6
|          |
|          |----X386
|---boot
|---lib
|          |----modules
|
|---dev
|---etc
|          |----skel
|          |----sysconfig
|---var
|          |----file
|          |----lib
|          |----local
|          |----lock
|          |----log
|          |
|          |----run
|          |
|          |----spool
|          |----tmp
|          |
|          |----catman
|---mnt
|---tmp


"/"
Root directory do not get confuse with root user account it is point where the Linux directory starts.(You may consider it as the main gate of a home)

"/root"
It is the super user home dir. Don't get confused with "/" dir.

"/home"
As Linux is the multiuser OS every user is given the personal dir to keep the related files, directories and configuration files and other stuffs. It is the playground for the user to do any thing like create, save and delete the files and installing the softwares. The config. files are saved with of '.' as the prefix which can be seen by giving '-a' as the argument to the ls command. The configuration file keeps the personal setting of the user like which environment is to start on login. Home dir contains the separate sub dir for each user.

You may consider the home dir as the House and user specific dir as the personal room of the individual family member in the house. Every member is free to do anything his/her room same in the linux.

"/bin"

It is the most essential directory of the linux operating system. It contains all the binaries for basic need of the system and command which are used by the multiple user. These can be used in single user mode even. This dir contains the commands which are used by the shell script indirectly.

"/sbin"
This dir is like the bin dir contains the basic binaries but these can be used by the 'super user' only.
e.g. shutdwon command which can be used by root user only

"/proc"
This dir contains the virtual files so called virtual file system.
It contains the the files which have the basic hardware, time, date and other system informations which keeps updated frequently. It contain bunch of numbers which have the information file related the particular process and the user login sessions etc.

"/usr"
This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use.
It also contains the c and c++ compiler header files in /usr/include subdir.

"/boot"
As the name suggests, this is the place where Linux keeps information that it needs when booting up. For example, this is where the Linux kernel is kept.

"/lib"
It contains the shared binaries at the root file system. It is just like the .DLL file in windows.

"/div"
It contains the devices which are available to your linux system. Like cdrom (/div/cdrom), harddrive(/div/hda).
Keep in mind linux treats the devices as the file.

"/etc"
This is the dir which contains the system and other config files. These files are the text files and can be edited manually.

"/var"
It contains the variables which keep changing constantly like log, mail, and spool.

"/mnt"
This is the mounting point of the other devices like harddrive, cdrom, pendrive etc. the need to be attached in the dir tree to access called mount point.

"/tmp"
This is the dir where a program writes the temporary files.

Saturday, August 28, 2010

Login, Logout and shutdown the linux system

I think you have installed the Linux on your system properly. Now the next step is logging in, out and shutdown of your system.

It is very simple when you have installed a GUI based Linux distro. But if you dont have the GUI based system then as you start your system then a login prompt will appear on the black screen.

Here you type the user name which password you know and press 'enter' now there will be a password prompt then give the respected user password you will get logged in.

If you logged in with 'root' user then you are the super user having all the authentication of the system. But if you are not a 'root' user then you have the limited rights assigned to the user with which you logged in. If you want to switch to the 'root' user then no problem.

Write 'su' on the command prompt and press 'enter'
then give the root password you will get in with root account....

*you can enter in other user mode even by su followed by the user name and give the password of that user.

To come back on the previous level(or logging out of root account) use 'exit' command.

To change the root password do as below:

root@ubuntu:/home/sachin# passwd
Enter new UNIX password: your password
Retype new UNIX password: repeat above password
passwd: password updated successfully

Now you have new root password.

Shutting down your Linux system:


You can shutdown a Linux by using the 'ALT+CTRL+DEL' key combination but it does not work in every system it depends on the 'init' program. But the following are the commands which generally works on most of the system if you are logged in as root user.

shutdown -h now --will shutdown your system immediately
shutdown -P now -- will work as above command
shutdown -r now --will make your system to reboot immediately
shutdown -r +10 --will make your system to reboot in 10 minutes
shutdown -r 14:00 --will make your system down and reboot at 2:00pm

Thursday, August 26, 2010

Starting with Linux

Before starting the linux you must be having the linux on your system so in this post i am going to tell you how to install the linux on your system,,,,,,,,,,,,,,

You can start with any distro on your system but if you are a beginner i will suggest you to install ubuntu on your system because is easy to install and use and having a good GUI even. For the same you will not feel odd first time on linux due to rich GUI of it.

So we start with installation .........


If you want to install it with of the CD/DVD then simply put the disk into the ROM and restart the computer and start the installation following the GUI instructions it will be very simple.

It will be same if you install it with USB pen drive even so no need to worry.

But as you come on the partition creation part there are two choice one to install by default. In this way the ubuntu will create the partition according to the setting done by the ubuntu community or developer team.

If you want to make partitions according to your choice the here are some basics to be kept in mind otherwise you will get in a great trouble or you may lose your existing data on the hard drive so be careful about it and follow as below....

There are two main partitions a Linux need one is Linux swap partition and other is Linux native partition. You can install Linux with other OS like Windows 98 ,NT ,2000, vista, xp but if you install it with NT or 2000 then extra care is to be taken because NT bootloader may conflict with LILO (Linux bootloader).

How much is to be assign to each partition:

Swap Partition:
It is the partition which is used by the Linux as the temporary memory to store the data when a processing need the RAM more than its capacity. Linux transfer the data temporarily on the swap partition which not frequently used. Generally the swap partition should be twice the capacity of your RAM or it depends on the architecture of your system. You can even create multiple partitions.

Native Partition:
In case of the Ubuntu you need to select the native partition atleast of 5GB the internal partition of this will be done by the Ubuntu itself. But if you are setting up a dedicated high performance server then you are recommended to do as follow..
1) / -Root size of 200MB
2) /usr -Holds local software. Min. 700MB and recommended 1.7GB or more..
3) /var -Holds mail, spool, log files recommended size 400 MB
4) /home -Rest of the disk where most of the data will be stored (user storage and multi user system)

Mounting Point:
A mounting point is the directory where the partition of the device is attached. For you Linux installation you need to specify the mount point. During installation you need to set the "/"(Root) as the mount point for your filesystem.

Now go next your installation will get start and you will be ready with your Linux system within few minutes based on the performance of your system. So enjoy it.

Wednesday, August 25, 2010

Switch from windows to linux

I am writing this blog for them who wants to switch Windows to LINUX .

But before going to the Linux you must be known about the basics of the Linux.

When I was in B.tech first year I came to know about the Linux first time through a workshop of Nibble Computer Society of my college Which taken by one of the senior. It was the workshop which made me interested towards Linux.

I switched to the Linux due to the following reason....

I had a IBM desktop which cd rom was not working (due to my merciless experiments over it) and its motherboard does not support the usb booting so i was in a great trouble because windows got corrupted every 25-30 days it was very big problem with me to format the system with borrowed cd rom
So After attending the workshop I came to know about the linux which gets corrupted very rarely then i decided to install the linux in my pc. In starting I faced many problem because I had no internet connecton which is very much required for the linux installed system but afterwards it became normal to me.

Now I enjoy the linux so much that I never dare to open the windows even because of the so many features of the linux.


Now I discuss the some of the features of linux over windows.....

1. The first thing of it, I like, is freely available and whole world contributes for its improvement so it is better as compare to the paid windows where a limited Engineers with limited minds works over it.

2. Require the least hardware ( a linux can run over 64MB of RAM, 512MB HD, and very low resolution monitor)

3. Can run for long time without restart or reboot of the system so good for the server puropse....

4. More secure as compare to the windows.

5. No fear of the virus threats and rarely get corrupted or hanged up.

6. Less risk of data lose due to power cuts as compare to the windows.

7. Whole source code is available so you can modify it according to your wish.

8. Supports multi user and multitasking.

9. Have a good interaction with hardware.

8. Now linux is available in various distro with very intacting gui even(like fedora,ubuntu,redhat,mendriva etc.).

After all this why should we go for windows(wasting of money). And I am sure that once you experience the linux you won't go back to the windows as myself.....I really hate windows.

How to make bootable pendrive

Sometimes if your laptop's CD/DVD rom get dead then it is very difficult to install the operating system......because there is no boot media so we need a boot media ....we may use pendrive for this purpose (bootable pendrive) but the question is that how to create the bootable usb media........



Don't worry i am going to tell you the procedure for various operating systems



First of all I will explain you about the linux it is easiest to make the bootable usb media for the linux..



Step1:

Take pen drive minimum 2GB put it into your desktop/laptop and transfer the data to your system because it is going to format.

Now right click on the icon of usm on the desktop and click on the 'format' option in the pop up menu.

After the format complete.



Step2:

Go to the 'Startup Disk Creator' by the following way......

System -> Administrator -> Startup Disk Creator click it a new window will open



Step3:

Select the source IMAGE of the CD/DVD by clicking on the other and click the 'Make Startup Disk'



Now the process will start and within 2-3 minutes you will be ready with 'Startup Bootable Usb Drive'

Wednesday, April 14, 2010

Linus Torvald s and prof. Tanenbaum

This is the conversation b/w Linux Torvalds and prof. Tanenbaum when Linus send the mail to the news group of the Minix (open source alternative of the Unix) so read this interesting conversation given below................

In August 25, 1991 the historic post was sent to the MINIX news group by Linus .....


From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Message-ID: <1991Aug25.205708.9541@klaava.Helsinki.FI>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki

Hello everybody out there using minix -
I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones. This has been brewing
since april, and is starting to get ready.I'd like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system(due to practical reasons)
among other things). I've currently ported bash(1.08) and gcc(1.40),and
things seem to work.This implies that I'll get something practical within a
few months, andI'd like to know what features most people would want. Any
suggestions are welcome, but I won't promise I'll implement them :-)
Linus (torvalds@kruuna.helsinki.fi)
PS. Yes - it's free of any minix code, and it has a multi-threaded fs.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks, as that's
all I have :-(.

As it is apparent from the posting, Linus himself didn't believe that his creation was going to be big enough to change computing forever. Linux version 0.01 was released by mid September 1991, and was put on the net. Enthusiasm gathered around this new kid on the block, and codes were downloaded, tested, tweaked, and returned to Linus. 0.02 came on October 5th, along with this famous declaration from Linus:


From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: Free minix-like kernel sources for 386-AT
Message-ID: <1991Oct5.054106.4647@klaava.Helsinki.FI>
Date: 5 Oct 91 05:41:06 GMT
Organization: University of Helsinki
Do you pine for the nice days of minix-1.1, when men were men and wrote their own device drivers?
Are you without a nice project and just dying to cut your teeth on a OS you can try to modify for your
needs? Are you finding it frustrating when everything works on minix? No more all-nighters to get a nifty program working? Then this post might be just for you :-)
As I mentioned a month(?)ago, I'm working on a free version of a minix-lookalike for AT-386 computers. It has
finally reached the stage where it's even usable (though may not be depending on
what you want), and I am willing to put out the sources for wider distribution. It is just version 0.02 (+1 (very
small) patch already), but I've successfully run bash/gcc/gnu-make/gnu-sed/compress etc under it.
Sources for this pet project of mine can be found at nic.funet.fi (128.214.6.100) in the directory /pub/OS/Linux.
The directory also contains some README-file and a couple of binaries to work under linux
(bash, update and gcc, what more can you ask for :-). Full kernel source is provided, as no minix code has been
used. Library sources are only partially free, so that cannot be distributed currently. The system is able to compile
"as-is" and has been known to work. Heh. Sources to the binaries (bash and gcc) can be found at the
same place in /pub/gnu.

Linux version 0.03 came in a few weeks. By December came version 0.10. Still Linux was little more than in skeletal form. It had only support for AT hard disks, had no login ( booted directly to bash). version 0.11 was much better with support for multilingual keyboards, floppy disk drivers, support for VGA,EGA, Hercules etc. The version numbers went directly from 0.12 to 0.95 and 0.96 and so on. Soon the code went worldwide via ftp sites at Finland and elsewhere.