Monday, August 9, 2010

Installing Apache Webserver on Fedora 12

1. Download the latest stable version of Apache webserver from the apache website
2. Create a directory apache2 in your home directory and copy the tar file there
(This is not mandatory, this is just to ease your installation)
[sridhar@Matrix ~]$ mkdir apache2
3. change to root
[sridhar@Matrix ~]$ su Password: [root@Matrix sridhar]#
4. copy the download file to the newly created apache2 folder
in this case
[root@Matrix ~]# cp /home/sridhar/Downloads/httpd-2.2.16.tar.gz /home/sridhar/apache
5. Unzip the file
[root@Matrix ~]# gzip -d httpd-2.2.16.tar.gz
6. Untar the file
[root@Matrix ~]# tar -xvf httpd-2.2.16.tar
7. [root@Matrix ~]# ./configure --prefix=/opt/apache2
This will install apache in /opt/apache2 location, default location is /usr/local/apache2
8. [root@Matrix ~]# make
9. [root@Matrix ~]# make install
10. [root@Matrix ~]# /opt/apache2/bin/apachectl start

Open a webbrowser and type in http://localhost, you must be able to see this

Sunday, August 1, 2010

Cron Job

Cron is a time-based job scheduler utility for automating certain tasks in Unix-like operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain time or date. It is commonly used to automate system maintenance or administration. For example if you would like to create backups of certain files or directories each night, you can use Cron to automate this.

Cron stores it's enteries in the crontab (cron table) file. This is generally located in the /etc directory. Each user can have their own crontab which would be stored in /var/spool/cron/. To edit a users crontab entry, simply log on to the system for that particular user and type crontab -e. The default editor for the 'crontab -e' command is vi. If you are not familiar with VI you can change the default editor by running the following command export VISUAL='editor'. Of course you must replace editor with your favorite text editor (nano, pico, joe etc). Or you could always learn how to use VI

Each line of a crontab file represents a job and is composed of a CRON expression, followed by a shell command to execute. Cron job has seven fields
1st field denotes Minutes ( 0 - 59 )
2nd field denotes Hours ( 0 - 23 )
3rd field denotes Day of the month ( 1 - 31 )
4th field denotes Month ( 1 - 12 ) or ( Jan, feb, mar, apr, ......)
5th field denotes Day of the week ( 0 - 7 ) or ( sun, mon, tue, wed, ......) Note ( 0 & 7 both denote Sunday)
6th field contains user User who runs the command.
7th field contains command Command that needs to be run. This field may contain multiple words or spaces.

There are several special predefined values which can be used to substitute the CRON expression.

Entry : @yearly (or @annually)
Description : Run once a year
Equivalent To : 0 0 1 1 *

Entry : @monthly
Description : Run once a month
Equivalent To : 0 0 1 * *

Entry : @weekly
Description : Run once a week
Equivalent To : 0 0 * * 0

Entry : @daily
Description : Run once a day
Equivalent To : 0 * * *

Entry : @midnight
Description : (same as @daily)
Equivalent To : 0 0 * * *

Entry : @hourly
Description : Run once an hour
Equivalent To : 0 * * * *

If both the dom and dow are specified, the command will be executed when
either of the events happen.
e.g.
* 12 16 * Mon root cmd
Will run cmd at midday every Monday and every 16th, and will produce the
same result as both of these entries put together would:
* 12 16 * * root cmd
* 12 * * Mon root cmd

Vixie 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).
e.g.
59 11 * * 1,2,3,4,5 root backup.sh
Will run backup.sh at 11:59 Monday, Tuesday, Wednesday, Thursday and Friday,
as will:
59 11 * * 1-5 root backup.sh

Cron also supports 'step' values.
A value of */2 in the dom field would mean the command runs every two days
and likewise, */5 in the hours field would mean the command runs every
5 hours.
e.g.
* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh

*/15 9-17 * * * root connection.test
Will run connection.test every 15 mins between the hours or 9am and 5pm

Lists can also be combined with each other, or with steps:

* 12 1-15,17,20-25 * * root cmd
Will run cmd every midday between the 1st and the 15th as well as the 20th
and 25th (inclusive) and also on the 17th of every month.

* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh

When using the names of weekdays or months, it isn't case sensitive, but only
the first three letters should be used, e.g. Mon, sun or Mar, jul.

Comments are allowed in crontabs, but they must be preceded with a '#', and
must be on a line by them self.

Controlling Access to cron

Cron has a built in feature of allowing you to specify who may, and who
may not use it. It does this by the use of /etc/cron.allow and /etc/cron.deny
files. These files work the same way as the allow/deny files for other
daemons do. To stop a user using cron, just put their name in cron.deny, to
allow a user put their name in the cron.allow. If you wanted to prevent all
users from using cron, you could add the line ALL to the cron.deny file:

root@Matrix # echo ALL >>/etc/cron.deny

If you want user cog to be able to use cron, you would add the line cog
to the cron.allow file:

root@Matrix # echo cog >>/etc/cron.allow

If there is neither a cron.allow nor a cron.deny file, then the use of cron
is unrestricted (i.e. every user can use it). If you were to put the name of
some users into the cron.allow file, without creating a cron.deny file, it
would have the same effect as creating a cron.deny file with ALL in it.
This means that any subsequent users that require cron access should be
put in to the cron.allow file.