Monday, September 21, 2009

FFmpeg PHP Installation in Linux



How to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source
This article shows how to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source. It should work on most systems, however may need some tweaking from system to sytem.

cd /usr/local/src

Download source tarballs:

wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://superb-west.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
wget http://www4.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2

Extract the tarballs:

tar zxvf lame-3.97.tar.gz
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz
tar zxvf flvtool2_1.0.5_rc6.tgz
tar jxvf essential-20061022.tar.bz2
tar jxvf ffmpeg-php-0.5.0.tbz2
tar zxvf flvtool2_1.0.5_rc6.tgz


Make a directory to store all the codecs:

mkdir /usr/local/lib/codecs/


Install any necessary packages:

yum install gcc gmake make libcpp libgcc libstdc++ gcc4 gcc4-c++ gcc4-gfortran
yum install subversion ruby ncurses-devel

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd /usr/local/src/mplayer
svn update
cd /usr/local/src

Copy codecs for mplayer:

mv /usr/local/src/essential-20061022/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/

If you are using secure tmp:

mkdir /usr/local/src/tmp
chmod 777 /usr/local/src/tmp
export TMPDIR=/usr/local/src/tmp

Installing Lame:

cd /usr/local/src/lame-3.97
./configure
make && make install

Installing Libogg:

cd /usr/local/src/libogg-1.1.3
./configure && make && make install

Installing libvorbis:

cd /usr/local/src/libvorbis-1.1.2
./configure && make && make install

Installing flvtool2:

cd /usr/local/src/flvtool2_1.0.5_rc6/
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

cd /usr/local/src/mplayer
./configure && make && make install

Installing ffmpeg:

cd /usr/local/src/ffmpeg/
./configure --enable-libmp3lame --enable-libogg --enable-libvorbis --disable-mmx --enable-shared
make && make install

ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51

Installing ffmpeg-php:

cd /usr/local/src/ffmpeg-php-0.5.0/
phpize
./configure
make
make install

Note: Make sure this is the correct php.ini for this server.

echo 'extension=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so' >> /usr/local/Zend/etc/php.ini

Restart apache:

service httpd restart

FFmpeg-PHP Installation in Linux



How to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source
This article shows how to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source. It should work on most systems, however may need some tweaking from system to sytem.

cd /usr/local/src

Download source tarballs:

wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://superb-west.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
wget http://www4.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2

Extract the tarballs:

tar zxvf lame-3.97.tar.gz
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz
tar zxvf flvtool2_1.0.5_rc6.tgz
tar jxvf essential-20061022.tar.bz2
tar jxvf ffmpeg-php-0.5.0.tbz2
tar zxvf flvtool2_1.0.5_rc6.tgz


Make a directory to store all the codecs:

mkdir /usr/local/lib/codecs/


Install any necessary packages:

yum install gcc gmake make libcpp libgcc libstdc++ gcc4 gcc4-c++ gcc4-gfortran
yum install subversion ruby ncurses-devel

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd /usr/local/src/mplayer
svn update
cd /usr/local/src

Copy codecs for mplayer:

mv /usr/local/src/essential-20061022/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/

If you are using secure tmp:

mkdir /usr/local/src/tmp
chmod 777 /usr/local/src/tmp
export TMPDIR=/usr/local/src/tmp

Installing Lame:

cd /usr/local/src/lame-3.97
./configure
make && make install

Installing Libogg:

cd /usr/local/src/libogg-1.1.3
./configure && make && make install

Installing libvorbis:

cd /usr/local/src/libvorbis-1.1.2
./configure && make && make install

Installing flvtool2:

cd /usr/local/src/flvtool2_1.0.5_rc6/
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

cd /usr/local/src/mplayer
./configure && make && make install

Installing ffmpeg:

cd /usr/local/src/ffmpeg/
./configure --enable-libmp3lame --enable-libogg --enable-libvorbis --disable-mmx --enable-shared
make && make install

ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51

Installing ffmpeg-php:

cd /usr/local/src/ffmpeg-php-0.5.0/
phpize
./configure
make
make install

Note: Make sure this is the correct php.ini for this server.

echo 'extension=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so' >> /usr/local/Zend/etc/php.ini

Restart apache:

service httpd restart

FFmpeg-PHP Installation


How to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source
This article shows how to install ffmpeg, ffmpeg-PHP, Mplayer, Mencoder, flv2tool, LAME MP3 Encoder, and Libog from source. It should work on most systems, however may need some tweaking from system to sytem.

cd /usr/local/src
Download source tarballs:
wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://superb-west.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
wget http://www4.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
Extract the tarballs:
tar zxvf lame-3.97.tar.gz
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz
tar zxvf flvtool2_1.0.5_rc6.tgz
tar jxvf essential-20061022.tar.bz2
tar jxvf ffmpeg-php-0.5.0.tbz2
tar zxvf flvtool2_1.0.5_rc6.tgz

Make a directory to store all the codecs:
mkdir /usr/local/lib/codecs/

Install any necessary packages:
yum install gcc gmake make libcpp libgcc libstdc++ gcc4 gcc4-c++ gcc4-gfortran
yum install subversion ruby ncurses-devel
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd /usr/local/src/mplayer
svn update
cd /usr/local/src
Copy codecs for mplayer:
mv /usr/local/src/essential-20061022/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
If you are using secure tmp:
mkdir /usr/local/src/tmp
chmod 777 /usr/local/src/tmp
export TMPDIR=/usr/local/src/tmp
Installing Lame:
cd /usr/local/src/lame-3.97
./configure
make && make install
Installing Libogg:
cd /usr/local/src/libogg-1.1.3
./configure && make && make install
Installing libvorbis:
cd /usr/local/src/libvorbis-1.1.2
./configure && make && make install
Installing flvtool2:
cd /usr/local/src/flvtool2_1.0.5_rc6/
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
cd /usr/local/src/mplayer
./configure && make && make install
Installing ffmpeg:
cd /usr/local/src/ffmpeg/
./configure --enable-libmp3lame --enable-libogg --enable-libvorbis --disable-mmx --enable-shared
make && make install
ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51
Installing ffmpeg-php:
cd /usr/local/src/ffmpeg-php-0.5.0/
phpize
./configure
make
make install
Note: Make sure this is the correct php.ini for this server.
echo 'extension=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ffmpeg.so' >> /usr/local/Zend/etc/php.ini
Restart apache:
service httpd restart

Friday, August 21, 2009

how to install imagemagick on linux server



How to install imagemagick on linux server


Here is a step-by-step guide on installing ImageMagick on most RedHat-based servers (RHEL, CentOS, Fedora, etc.):


You can install ImageMagick from source. However, if don't have a proper development environment or if you're anxious to get started, download a ready-to-run Unix or Windows executable. Before you download, you may want to review recent changes to the ImageMagick distribution.

You Can Download ImageMagick Rpm from the following Link
http://www.imagemagick.org/download/linux/fedora/i386/ImageMagick-6.5.4-10.i386.rpm
ImageMagick RPM's are self-installing. Simply type the following command and you're ready to start using ImageMagick:
$magick> rpm -Uvh ImageMagick-6.5.4-10.i386.rpm

For other systems, create (or choose) a directory to install the package into and change to that directory, for example:
$magick>
cd $HOME

Next, extract the contents of the package. For example:

$magick> tar xvfz ImageMagick.tar.gz

Set the MAGICK_HOME environment variable to the path where you extracted the ImageMagick files. For example:

$magick> export MAGICK_HOME="$HOME/ImageMagick-6.5.4"

If the bin subdirectory of the extracted package is not already in your executable search path, add it to your PATH environment variable. For example:

$magick> export PATH="$MAGICK_HOME/bin:$PATH"

On Linux and Solaris machines add $MAGICK_HOME/lib to the LD_LIBRARY_PATH environment variable:

$magick>LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$MAGICK_HOME/lib" $magick> export LD_LIBRARY_PATH

Finally, to verify ImageMagick is working properly, type the following on the command line:

$magick> convert logo: logo.gif $magick> identify logo.gif $magick> display logo.gif

Congratulations, you have a working ImageMagick distribution under Unix or Linux and you are ready to use ImageMagick to convert, compose, or edit your images or perhaps you'll want to use one of the Application Program Interfaces for C, C++, Perl, and others.

Or

yum install ImageMagick

after you send this shell command you will be ask this.. just say yes
Total download size: 15 M
Is this ok [y/N]: y

how to install imagemagick on linux server



How to install imagemagick on linux server


Here is a step-by-step guide on installing ImageMagick on most RedHat-based servers (RHEL, CentOS, Fedora, etc.):


You can install ImageMagick from source. However, if don't have a proper development environment or if you're anxious to get started, download a ready-to-run Unix or Windows executable. Before you download, you may want to review recent changes to the ImageMagick distribution.

You Can Download ImageMagick Rpm from the following Link
http://www.imagemagick.org/download/linux/fedora/i386/ImageMagick-6.5.4-10.i386.rpm
ImageMagick RPM's are self-installing. Simply type the following command and you're ready to start using ImageMagick:
$magick> rpm -Uvh ImageMagick-6.5.4-10.i386.rpm

For other systems, create (or choose) a directory to install the package into and change to that directory, for example:
$magick>
cd $HOME

Next, extract the contents of the package. For example:

$magick> tar xvfz ImageMagick.tar.gz

Set the MAGICK_HOME environment variable to the path where you extracted the ImageMagick files. For example:

$magick> export MAGICK_HOME="$HOME/ImageMagick-6.5.4"

If the bin subdirectory of the extracted package is not already in your executable search path, add it to your PATH environment variable. For example:

$magick> export PATH="$MAGICK_HOME/bin:$PATH"

On Linux and Solaris machines add $MAGICK_HOME/lib to the LD_LIBRARY_PATH environment variable:

$magick>LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$MAGICK_HOME/lib" $magick> export LD_LIBRARY_PATH

Finally, to verify ImageMagick is working properly, type the following on the command line:

$magick> convert logo: logo.gif $magick> identify logo.gif $magick> display logo.gif

Congratulations, you have a working ImageMagick distribution under Unix or Linux and you are ready to use ImageMagick to convert, compose, or edit your images or perhaps you'll want to use one of the Application Program Interfaces for C, C++, Perl, and others.

Or

yum install ImageMagick

after you send this shell command you will be ask this.. just say yes
Total download size: 15 M
Is this ok [y/N]: y

Fedora : ImageMagick Installation


Here is a step-by-step guide on installing ImageMagick on most RedHat-based servers (RHEL, CentOS, Fedora, etc.):

You can install ImageMagick from source. However, if don't have a proper development environment or if you're anxious to get started, download a ready-to-run Unix or Windows executable. Before you download, you may want to review recent changes to the ImageMagick distribution.

You Can Download ImageMagick Rpm from the following Link
http://www.imagemagick.org/download/linux/fedora/i386/ImageMagick-6.5.4-10.i386.rpm
ImageMagick RPM's are self-installing. Simply type the following command and you're ready to start using ImageMagick:
$magick> rpm -Uvh ImageMagick-6.5.4-10.i386.rpm

For other systems, create (or choose) a directory to install the package into and change to that directory, for example:
$magick>
cd $HOME

Next, extract the contents of the package. For example:
$magick> tar xvfz ImageMagick.tar.gz
Set the MAGICK_HOME environment variable to the path where you extracted the ImageMagick files. For example:
$magick> export MAGICK_HOME="$HOME/ImageMagick-6.5.4"
If the bin subdirectory of the extracted package is not already in your executable search path, add it to your PATH environment variable. For example:
$magick> export PATH="$MAGICK_HOME/bin:$PATH"
On Linux and Solaris machines add $MAGICK_HOME/lib to the LD_LIBRARY_PATH environment variable:
$magick>LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$MAGICK_HOME/lib" $magick> export LD_LIBRARY_PATH
Finally, to verify ImageMagick is working properly, type the following on the command line:
$magick> convert logo: logo.gif $magick> identify logo.gif $magick> display logo.gif
Congratulations, you have a working ImageMagick distribution under Unix or Linux and you are ready to use ImageMagick to convert, compose, or edit your images or perhaps you'll want to use one of the Application Program Interfaces for C, C++, Perl, and others.
Or

yum install ImageMagick

after you send this shell command you will be ask this.. just say yes
Total download size: 15 M
Is this ok [y/N]: y

How to install zimbra on Centos





This tutorial shows how to set up Zimbra Collaboration Suite - Open Source Edition on CentOS. This tutorial covers installation of CentOS, dependencies for ZCS and setup of Split DNS when working behind a firewall. This tutorial is based on the way I set this server up and is only a suggestion. It carries no guarantees and it is highly suggested that you do this on a test server first to verify functionality. If you don't have a test server available you should download VMWare Server 1.0 and perform this tutorial on a test virtual server.


[1]Requirements
:

To install this system you will need the following:
CentOS 5 DVD or CD ISO images which are available at http://isoredirect.centos.org/centos/5/isos/i386/
High-speed Internet connection
Insert your CentOS install CD into your system and boot from it. Hit Enter to start the installation.

After Completing Centos Installation follow these steps
The last step is to shutoff some services that will interfere with ZCS.


chkconfig sendmail off
chkconfig ip6tables off
chkconfig iptables off

We need one package before we can continue:
yum install libtool-ltdl
This completes the base installation of CentOS. On the next page we will setup Split DNS which is essential for ZCS. Go ahead and reboot, and fill up that coffee cup.

[2]Installation Of Split DNS


This part of installation is working off of the assumption that you are behind a firewall. If you are not behind a firewall (not recommended) you can skip this part of the installation.
I need to give credit where it is due. The chroot portion of this tutorial is adapted from Sebastien Wains. His CentOS Bind Chroot tutorial can be found at http://www.wains.be/index.php/2007/12/13/centos-5-chroot-dns-with-bind/. The Split DNS tutorial is adapted from the Zimbra Wiki and can be found at http://wiki.zimbra.com/index.php?title=Split_dns.

yum install bind bind-chroot bind-libs bind-utils

REMINDER: Be sure to use the ip address and hostname/FQDN that is appropriate for your installation.

Create the /var/named/chroot/etc/named.conf file

vim /var/named/chroot/etc/named.conf

options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
forwarders { 192.168.0.10 ; };
};
include "/etc/rndc.key";
// We are the master server for mail.geekdept.com
zone "mail.geekdept.com" {
type master;
file "db.mail.geekdept.com";
};


The ip address for forwarders should be the ip address of your dns server.

Now you need to create your /var/named/chroot/var/named/db.mail.geekdept.com file

;
; Addresses and other host information.
;
@ IN SOA mail.geekdept.com. hostmaster.mail.geekdept.com. (
10118 ; Serial
43200 ; Refresh
3600 ; Retry
3600000 ; Expire
2592000 ) ; Minimum
; Define the nameservers and the mail servers
IN NS 192.168.0.45
IN A 192.168.0.45
IN MX 10 mail.geekdept.com.


Change your resolv.conf to use your mail server's IP address as it's primary DNS.
vim /etc/resolv.conf

search geekdept.com
nameserver 192.168.0.45
Start named on your server
/etc/init.d/named start
Enable autostart for named.
chkconfig named on
To verify that it is working do the following:
nslookup mail.geekdept.com

It should return something similar to this:
Server: 192.168.0.45
Address: 192.168.0.45#53
Name: mail.geekdept.com
Address: 192.168.0.45

Notice that the ip address returned is the same as the local machine. That means success.

Now we can move on to installing ZCS.

[3]
Installation Of Zimbra Collaboration Suite

You will need to download ZCS from the Zimbra website.
cd/tmpwget http://files.zimbra.com/downloads/5.0.2_/zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz

Next untar, change into the directory of the installer and run the installer.

tar xvzf zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz
cd zcs-5.0.2_GA_1975.RHEL5.20080130221917
./install.sh

The output should look something like:

zimbra-ldap...NOT FOUND
zimbra-logger...NOT FOUND
zimbra-mta...NOT FOUND
zimbra-snmp...NOT FOUND
zimbra-store...NOT FOUND
zimbra-apache...NOT FOUND
zimbra-spell...NOT FOUND
zimbra-proxy...NOT FOUND
zimbra-archiving...NOT FOUND
zimbra-cluster...NOT FOUND
zimbra-core...NOT FOUND



Read through the license agreement and hit enter.

The output should be similar to:

Checking for prerequisites...
NPTL...FOUND
sudo...FOUND sudo-1.6.7p12-10
libidn...FOUND libidn-0.6.5-1.1
fetchmail...FOUND fetchmail-6.3.6-1.1
gmp...FOUND gmp-4.1.4-10
compat-libstdc++-296...FOUND compat-libstdc++-296-2.96-138
compat-libstdc++-33...FOUND compat-libstdc++-33-3.2.3-61
libtool-ltdl...FOUND libtool-ltdl-1.5.22-6.1
/usr/lib/libstdc++.so.6...FOUND
Prerequisite check complete.
Checking for standard system perl...
perl-5.8.8...FOUND start system perl-5.8.8

Checking for installable packages

Found zimbra-core
Found zimbra-ldap
Found zimbra-logger
Found zimbra-mta
Found zimbra-snmp
Found zimbra-store
Found zimbra-apache
Found zimbra-spell
Found zimbra-proxy


Next you need to select the packages to install. The defaults are listed in teh brackets so you can just press enter for every question.

Install zimbra-ldap [Y]Install zimbra-logger [Y]

Install zimbra-mta [Y]

Install zimbra-snmp [Y]

Install zimbra-store [Y]

Install zimbra-apache [Y]

Install zimbra-spell [Y]

Install zimbra-proxy [N]


You will see a warning like this:You appear to be installing packages on a platform different
than the platform for which they were built

This platform is CentOS5
Packages found: zimbra-core-5.0.2_GA_1975.RHEL5-20080130221917.i386.rpm
This may or may not work

Install anyway? [N]Y

The system will be modified. Continue? [N] Y


The installation takes a little bit so if you are running low on coffee or need a potty break now is the time to take it. :)

Once the install is finished you are presented with the Main Menu. It looks like this:


Notice the asterisks next to the Admin Password. You need to set the Admin Password before you complete the install. To do this enter 3 at the prompt and hit enter. The menu changes to:


Now you choose 4. You will be prompted to change the password. After you change the password hit r which will take you back to the previous menu. Enter a at the prompt to save the configuration.

The installation will complete and you will be all set to access the administrative web interface.

[4] ZCS Admin Web Interface


Just like Falko I'm just going to give a brief screenshot tour and leave it up to you to get more information from the Zimbra Admin Guide and the Zimbra Wiki.

Administration Login


You can access the admin web interface by going to https://you.domain.com:7071.


Note: The web interface is accessed via ssl. Make sure you put https otherwise you won't be able to access the site.


The web interface is fairly easy to navigate. That'll you will completed installing Zimbra Email Server


How to install zimbra on Centos





This tutorial shows how to set up Zimbra Collaboration Suite - Open Source Edition on CentOS. This tutorial covers installation of CentOS, dependencies for ZCS and setup of Split DNS when working behind a firewall. This tutorial is based on the way I set this server up and is only a suggestion. It carries no guarantees and it is highly suggested that you do this on a test server first to verify functionality. If you don't have a test server available you should download VMWare Server 1.0 and perform this tutorial on a test virtual server.


[1]Requirements
:

To install this system you will need the following:
CentOS 5 DVD or CD ISO images which are available at http://isoredirect.centos.org/centos/5/isos/i386/
High-speed Internet connection
Insert your CentOS install CD into your system and boot from it. Hit Enter to start the installation.

After Completing Centos Installation follow these steps
The last step is to shutoff some services that will interfere with ZCS.


chkconfig sendmail off
chkconfig ip6tables off
chkconfig iptables off

We need one package before we can continue:
yum install libtool-ltdl
This completes the base installation of CentOS. On the next page we will setup Split DNS which is essential for ZCS. Go ahead and reboot, and fill up that coffee cup.

[2]Installation Of Split DNS


This part of installation is working off of the assumption that you are behind a firewall. If you are not behind a firewall (not recommended) you can skip this part of the installation.
I need to give credit where it is due. The chroot portion of this tutorial is adapted from Sebastien Wains. His CentOS Bind Chroot tutorial can be found at http://www.wains.be/index.php/2007/12/13/centos-5-chroot-dns-with-bind/. The Split DNS tutorial is adapted from the Zimbra Wiki and can be found at http://wiki.zimbra.com/index.php?title=Split_dns.

yum install bind bind-chroot bind-libs bind-utils

REMINDER: Be sure to use the ip address and hostname/FQDN that is appropriate for your installation.

Create the /var/named/chroot/etc/named.conf file

vim /var/named/chroot/etc/named.conf

options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
forwarders { 192.168.0.10 ; };
};
include "/etc/rndc.key";
// We are the master server for mail.geekdept.com
zone "mail.geekdept.com" {
type master;
file "db.mail.geekdept.com";
};


The ip address for forwarders should be the ip address of your dns server.

Now you need to create your /var/named/chroot/var/named/db.mail.geekdept.com file

;
; Addresses and other host information.
;
@ IN SOA mail.geekdept.com. hostmaster.mail.geekdept.com. (
10118 ; Serial
43200 ; Refresh
3600 ; Retry
3600000 ; Expire
2592000 ) ; Minimum
; Define the nameservers and the mail servers
IN NS 192.168.0.45
IN A 192.168.0.45
IN MX 10 mail.geekdept.com.


Change your resolv.conf to use your mail server's IP address as it's primary DNS.
vim /etc/resolv.conf

search geekdept.com
nameserver 192.168.0.45
Start named on your server
/etc/init.d/named start
Enable autostart for named.
chkconfig named on
To verify that it is working do the following:
nslookup mail.geekdept.com

It should return something similar to this:
Server: 192.168.0.45
Address: 192.168.0.45#53
Name: mail.geekdept.com
Address: 192.168.0.45

Notice that the ip address returned is the same as the local machine. That means success.

Now we can move on to installing ZCS.

[3]
Installation Of Zimbra Collaboration Suite

You will need to download ZCS from the Zimbra website.
cd/tmpwget http://files.zimbra.com/downloads/5.0.2_/zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz

Next untar, change into the directory of the installer and run the installer.

tar xvzf zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz
cd zcs-5.0.2_GA_1975.RHEL5.20080130221917
./install.sh

The output should look something like:

zimbra-ldap...NOT FOUND
zimbra-logger...NOT FOUND
zimbra-mta...NOT FOUND
zimbra-snmp...NOT FOUND
zimbra-store...NOT FOUND
zimbra-apache...NOT FOUND
zimbra-spell...NOT FOUND
zimbra-proxy...NOT FOUND
zimbra-archiving...NOT FOUND
zimbra-cluster...NOT FOUND
zimbra-core...NOT FOUND



Read through the license agreement and hit enter.

The output should be similar to:

Checking for prerequisites...
NPTL...FOUND
sudo...FOUND sudo-1.6.7p12-10
libidn...FOUND libidn-0.6.5-1.1
fetchmail...FOUND fetchmail-6.3.6-1.1
gmp...FOUND gmp-4.1.4-10
compat-libstdc++-296...FOUND compat-libstdc++-296-2.96-138
compat-libstdc++-33...FOUND compat-libstdc++-33-3.2.3-61
libtool-ltdl...FOUND libtool-ltdl-1.5.22-6.1
/usr/lib/libstdc++.so.6...FOUND
Prerequisite check complete.
Checking for standard system perl...
perl-5.8.8...FOUND start system perl-5.8.8

Checking for installable packages

Found zimbra-core
Found zimbra-ldap
Found zimbra-logger
Found zimbra-mta
Found zimbra-snmp
Found zimbra-store
Found zimbra-apache
Found zimbra-spell
Found zimbra-proxy


Next you need to select the packages to install. The defaults are listed in teh brackets so you can just press enter for every question.

Install zimbra-ldap [Y]Install zimbra-logger [Y]

Install zimbra-mta [Y]

Install zimbra-snmp [Y]

Install zimbra-store [Y]

Install zimbra-apache [Y]

Install zimbra-spell [Y]

Install zimbra-proxy [N]


You will see a warning like this:You appear to be installing packages on a platform different
than the platform for which they were built

This platform is CentOS5
Packages found: zimbra-core-5.0.2_GA_1975.RHEL5-20080130221917.i386.rpm
This may or may not work

Install anyway? [N]Y

The system will be modified. Continue? [N] Y


The installation takes a little bit so if you are running low on coffee or need a potty break now is the time to take it. :)

Once the install is finished you are presented with the Main Menu. It looks like this:


Notice the asterisks next to the Admin Password. You need to set the Admin Password before you complete the install. To do this enter 3 at the prompt and hit enter. The menu changes to:


Now you choose 4. You will be prompted to change the password. After you change the password hit r which will take you back to the previous menu. Enter a at the prompt to save the configuration.

The installation will complete and you will be all set to access the administrative web interface.

[4] ZCS Admin Web Interface


Just like Falko I'm just going to give a brief screenshot tour and leave it up to you to get more information from the Zimbra Admin Guide and the Zimbra Wiki.

Administration Login


You can access the admin web interface by going to https://you.domain.com:7071.


Note: The web interface is accessed via ssl. Make sure you put https otherwise you won't be able to access the site.


The web interface is fairly easy to navigate. That'll you will completed installing Zimbra Email Server


Zimbra Collaboration Suite Open Source Edition On CentOS


This tutorial shows how to set up Zimbra Collaboration Suite - Open Source Edition on CentOS. This tutorial covers installation of CentOS, dependencies for ZCS and setup of Split DNS when working behind a firewall. This tutorial is based on the way I set this server up and is only a suggestion. It carries no guarantees and it is highly suggested that you do this on a test server first to verify functionality. If you don't have a test server available you should download VMWare Server 1.0 and perform this tutorial on a test virtual server.


[1]Requirements
:

To install this system you will need the following:
CentOS 5 DVD or CD ISO images which are available at http://isoredirect.centos.org/centos/5/isos/i386/
High-speed Internet connection
Insert your CentOS install CD into your system and boot from it. Hit Enter to start the installation.

After Completing Centos Installation follow these steps
The last step is to shutoff some services that will interfere with ZCS.

chkconfig sendmail off
chkconfig ip6tables off
chkconfig iptables off


We need one package before we can continue:
yum install libtool-ltdl
This completes the base installation of CentOS. On the next page we will setup Split DNS which is essential for ZCS. Go ahead and reboot, and fill up that coffee cup.

[2]Installation Of Split DNS

This part of installation is working off of the assumption that you are behind a firewall. If you are not behind a firewall (not recommended) you can skip this part of the installation.
I need to give credit where it is due. The chroot portion of this tutorial is adapted from Sebastien Wains. His CentOS Bind Chroot tutorial can be found at http://www.wains.be/index.php/2007/12/13/centos-5-chroot-dns-with-bind/. The Split DNS tutorial is adapted from the Zimbra Wiki and can be found at http://wiki.zimbra.com/index.php?title=Split_dns.
yum install bind bind-chroot bind-libs bind-utils
REMINDER: Be sure to use the ip address and hostname/FQDN that is appropriate for your installation.
Create the /var/named/chroot/etc/named.conf file
vim /var/named/chroot/etc/named.conf
options {
       directory "/var/named";
       dump-file "/var/named/data/cache_dump.db";
       statistics-file "/var/named/data/named_stats.txt";
forwarders { 192.168.0.10 ; };
};
include "/etc/rndc.key";
// We are the master server for mail.geekdept.com
zone "mail.geekdept.com" {
    type master;
    file "db.mail.geekdept.com";
};

The ip address for forwarders should be the ip address of your dns server.
Now you need to create your /var/named/chroot/var/named/db.mail.geekdept.com file
;
;       Addresses and other host information.
;
@       IN      SOA     mail.geekdept.com. hostmaster.mail.geekdept.com. (
                               10118      ; Serial
                               43200      ; Refresh
                               3600       ; Retry
                               3600000    ; Expire
                               2592000 )  ; Minimum
;       Define the nameservers and the mail servers
               IN      NS      192.168.0.45
               IN      A       192.168.0.45
 IN      MX      10 mail.geekdept.com.


Change your resolv.conf to use your mail server's IP address as it's primary DNS.
vim /etc/resolv.conf 

search geekdept.com
nameserver 192.168.0.45
Start named on your server
/etc/init.d/named start 
Enable autostart for named.
chkconfig named on 
To verify that it is working do the following:
nslookup mail.geekdept.com 

It should return something similar to this:
Server:         192.168.0.45
Address:        192.168.0.45#53
Name:   mail.geekdept.com
Address: 192.168.0.45

Notice that the ip address returned is the same as the local machine. That means success.
Now we can move on to installing ZCS.

[3] Installation Of Zimbra Collaboration Suite

You will need to download ZCS from the Zimbra website.
cd/tmpwget http://files.zimbra.com/downloads/5.0.2_/zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz 
Next untar, change into the directory of the installer and run the installer.
tar xvzf zcs-5.0.2_GA_1975.RHEL5.20080130221917.tgz
cd zcs-5.0.2_GA_1975.RHEL5.20080130221917
./install.sh
The output should look something like:
zimbra-ldap...NOT FOUND
zimbra-logger...NOT FOUND
zimbra-mta...NOT FOUND
zimbra-snmp...NOT FOUND
zimbra-store...NOT FOUND
zimbra-apache...NOT FOUND
zimbra-spell...NOT FOUND
zimbra-proxy...NOT FOUND
zimbra-archiving...NOT FOUND
zimbra-cluster...NOT FOUND
zimbra-core...NOT FOUND 

Read through the license agreement and hit enter.
The output should be similar to:
Checking for prerequisites...
NPTL...FOUND
sudo...FOUND sudo-1.6.7p12-10
libidn...FOUND libidn-0.6.5-1.1
fetchmail...FOUND fetchmail-6.3.6-1.1
gmp...FOUND gmp-4.1.4-10
compat-libstdc++-296...FOUND compat-libstdc++-296-2.96-138
compat-libstdc++-33...FOUND compat-libstdc++-33-3.2.3-61
libtool-ltdl...FOUND libtool-ltdl-1.5.22-6.1
/usr/lib/libstdc++.so.6...FOUND
Prerequisite check complete.
Checking for standard system perl...
perl-5.8.8...FOUND start system perl-5.8.8

Checking for installable packages

Found zimbra-core
Found zimbra-ldap
Found zimbra-logger
Found zimbra-mta
Found zimbra-snmp
Found zimbra-store
Found zimbra-apache
Found zimbra-spell
Found zimbra-proxy
Next you need to select the packages to install. The defaults are listed in teh brackets so you can just press enter for every question.
Install zimbra-ldap [Y]

Install zimbra-logger [Y]

Install zimbra-mta [Y]

Install zimbra-snmp [Y]

Install zimbra-store [Y]

Install zimbra-apache [Y]

Install zimbra-spell [Y]

Install zimbra-proxy [N]
You will see a warning like this:

You appear to be installing packages on a platform different
than the platform for which they were built

This platform is CentOS5
Packages found: zimbra-core-5.0.2_GA_1975.RHEL5-20080130221917.i386.rpm
This may or may not work

Install anyway? [N] Y

The system will be modified. Continue? [N] Y
The installation takes a little bit so if you are running low on coffee or need a potty break now is the time to take it. :)
Once the install is finished you are presented with the Main Menu. It looks like this:

Notice the asterisks next to the Admin Password. You need to set the Admin Password before you complete the install. To do this enter 3 at the prompt and hit enter. The menu changes to:
Now you choose 4. You will be prompted to change the password. After you change the password hit r which will take you back to the previous menu. Enter a at the prompt to save the configuration.
The installation will complete and you will be all set to access the administrative web interface.

[4] ZCS Admin Web Interface

Just like Falko I'm just going to give a brief screenshot tour and leave it up to you to get more information from the Zimbra Admin Guide and the Zimbra Wiki.

Administration Login

You can access the admin web interface by going to https://you.domain.com:7071.

Note: The web interface is accessed via ssl. Make sure you put https otherwise you won't be able to access the site.

The web interface is fairly easy to navigate. That'll you will completed installing Zimbra Email Server

Tuesday, March 3, 2009

how to add jobs to cron under linux or unix



HowTo Add Jobs To cron Under Linux or UNIX?


 How do I add cron job under Linux or UNIX like operating system?


Cron job are used to schedule commands to be executed periodically. You can setup setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.

crontab is the command used to install, deinstall or list the tables (cron configuration file) used to drive the cron daemon in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

 

Different Types of cron Configuration


There are two different types of configuration files:


  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.

  2. The user crontabs: User can installer their own jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab


How Do I Install / Create / Edit My Own Cronjobs?


To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e

Syntax of crontab (Field Description)


Your cron job looks as follows for user jobs:

 
1 2 3 4 5 /path/to/command arg1 arg2
 

OR

 
1 2 3 4 5 /root/backup.sh
 

Where,


  • 1: Minute (0-59)

  • 2: Hours (0-23)

  • 3: Day (0-31)

  • 4: Month (0-12 [12 == December])

  • 5: Day of the week(0-7 [7 or 0 == sunday])

  • /path/to/command - Script or command name to schedule


Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Your cron job looks as follows for system jobs:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

Example: Install Backup Job Script


If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e

Append the following entry:
0 3 * * * /root/backup.sh

Save and close the file.

More Examples


To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command

Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh

Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php

Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl

Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand

How Do I Use Operators?


An operator allows you to specifying multiple values in a field. There are three operators:


  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.

  2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".

  3. The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,....,13,14,15" using the comma operator.


How Do I Disable Email Output?


By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1

To mail output to particular email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1

Task: List All Your crontab Jobs


Type the following command :
# crontab -l
# crontab -u username -l

To remove or erase all crontab jobs use the following command:
# crontab -r
crontab -r -u username

Use special string to save time


Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.








































Special stringMeaning
@rebootRun once, at startup.
@yearlyRun once a year, "0 0 1 1 *".
@annually(same as @yearly)
@monthlyRun once a month, "0 0 1 * *".
@weeklyRun once a week, "0 0 * * 0".
@dailyRun once a day, "0 0 * * *".
@midnight(same as @daily)
@hourly Run once an hour, "0 * * * *".

Run ntpdate every hour:
@hourly /path/to/ntpdate

Make a backup everyday:
@daily /path/to/backup/script.sh

Understanding /etc/crontab file and /etc/cron.d/* directories


/etc/crontab is system crontabs file. Usually only used by root user or daemons to configure system wide jobs. All individual user must must use crontab command to install and edit their jobs as described above. /var/spool/cron/ or /var/cron/tabs/ is directory for personal user crontab files. It must be backup with users home directory.

Understanding Default /etc/crontab


Typical /etc/crontab file entries:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

First, the environment must be defined. If the shell line is omitted, cron will use the default, which is sh. If the PATH variable is omitted, no default will be used and file locations will need to be absolute. If HOME is omitted, cron will use the invoking users home directory.

(3)

Additionally, cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob here. As a root user or superuser you can use following directories to configure cronjobs. You can directly drop your scripts here. run-parts command run scripts or programs in a directory via /etc/crontab




























DirectoryDescription
/etc/cron.d/ Put all scripts here and call them from /etc/crontab file.
/etc/cron.daily/ Run all scripts once a day
/etc/cron.hourly/ Run all scripts once an hour
/etc/cron.monthly/ Run all scripts once a month
/etc/cron.weekly/Run all scripts once a week

How do I Use Above Directories To Put My Scripts?


Here is a sample shell script (clean.cache) to clean up cached files every 10 days. This script is directly created at /etc/cron.daliy/ directory i.e. create a file called /etc/cron.daily/clean.cache:

 #!/bin/bash
# A sample shell script to clean cached file from lighttpd web server
CROOT="/tmp/cachelighttpd/"
DAYS=10
LUSER="lighttpd"
LGROUP="lighttpd"
 
# start cleaning
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm
 
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
/bin/mkdir -p $CROOT
/bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi

How Do I Backup Installed Cronjobs Entries?


Simply type the following command to backup your cronjobs to a nas server mounted at /nas01/backup/cron/users.root.bakup directory:
# crontab -l > /nas01/backup/cron/users.root.bakup
# crontab -u userName -l > /nas01/backup/cron/users.userName.bakup

 


how to add jobs to cron under linux or unix



HowTo Add Jobs To cron Under Linux or UNIX?


 How do I add cron job under Linux or UNIX like operating system?


Cron job are used to schedule commands to be executed periodically. You can setup setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.

crontab is the command used to install, deinstall or list the tables (cron configuration file) used to drive the cron daemon in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

 

Different Types of cron Configuration


There are two different types of configuration files:


  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.

  2. The user crontabs: User can installer their own jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab


How Do I Install / Create / Edit My Own Cronjobs?


To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e

Syntax of crontab (Field Description)


Your cron job looks as follows for user jobs:

 
1 2 3 4 5 /path/to/command arg1 arg2
 

OR

 
1 2 3 4 5 /root/backup.sh
 

Where,


  • 1: Minute (0-59)

  • 2: Hours (0-23)

  • 3: Day (0-31)

  • 4: Month (0-12 [12 == December])

  • 5: Day of the week(0-7 [7 or 0 == sunday])

  • /path/to/command - Script or command name to schedule


Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Your cron job looks as follows for system jobs:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

Example: Install Backup Job Script


If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e

Append the following entry:
0 3 * * * /root/backup.sh

Save and close the file.

More Examples


To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command

Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh

Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php

Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl

Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand

How Do I Use Operators?


An operator allows you to specifying multiple values in a field. There are three operators:


  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.

  2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".

  3. The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,....,13,14,15" using the comma operator.


How Do I Disable Email Output?


By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1

To mail output to particular email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1

Task: List All Your crontab Jobs


Type the following command :
# crontab -l
# crontab -u username -l

To remove or erase all crontab jobs use the following command:
# crontab -r
crontab -r -u username

Use special string to save time


Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.








































Special stringMeaning
@rebootRun once, at startup.
@yearlyRun once a year, "0 0 1 1 *".
@annually(same as @yearly)
@monthlyRun once a month, "0 0 1 * *".
@weeklyRun once a week, "0 0 * * 0".
@dailyRun once a day, "0 0 * * *".
@midnight(same as @daily)
@hourly Run once an hour, "0 * * * *".

Run ntpdate every hour:
@hourly /path/to/ntpdate

Make a backup everyday:
@daily /path/to/backup/script.sh

Understanding /etc/crontab file and /etc/cron.d/* directories


/etc/crontab is system crontabs file. Usually only used by root user or daemons to configure system wide jobs. All individual user must must use crontab command to install and edit their jobs as described above. /var/spool/cron/ or /var/cron/tabs/ is directory for personal user crontab files. It must be backup with users home directory.

Understanding Default /etc/crontab


Typical /etc/crontab file entries:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

First, the environment must be defined. If the shell line is omitted, cron will use the default, which is sh. If the PATH variable is omitted, no default will be used and file locations will need to be absolute. If HOME is omitted, cron will use the invoking users home directory.

(3)

Additionally, cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob here. As a root user or superuser you can use following directories to configure cronjobs. You can directly drop your scripts here. run-parts command run scripts or programs in a directory via /etc/crontab




























DirectoryDescription
/etc/cron.d/ Put all scripts here and call them from /etc/crontab file.
/etc/cron.daily/ Run all scripts once a day
/etc/cron.hourly/ Run all scripts once an hour
/etc/cron.monthly/ Run all scripts once a month
/etc/cron.weekly/Run all scripts once a week

How do I Use Above Directories To Put My Scripts?


Here is a sample shell script (clean.cache) to clean up cached files every 10 days. This script is directly created at /etc/cron.daliy/ directory i.e. create a file called /etc/cron.daily/clean.cache:

 #!/bin/bash
# A sample shell script to clean cached file from lighttpd web server
CROOT="/tmp/cachelighttpd/"
DAYS=10
LUSER="lighttpd"
LGROUP="lighttpd"
 
# start cleaning
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm
 
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
/bin/mkdir -p $CROOT
/bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi

How Do I Backup Installed Cronjobs Entries?


Simply type the following command to backup your cronjobs to a nas server mounted at /nas01/backup/cron/users.root.bakup directory:
# crontab -l > /nas01/backup/cron/users.root.bakup
# crontab -u userName -l > /nas01/backup/cron/users.userName.bakup

 


Jobs To cron Under Linux or UNIX

HowTo: Add Jobs To cron Under Linux or UNIX?

 How do I add cron job under Linux or UNIX like operating system?

Cron job are used to schedule commands to be executed periodically. You can setup setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.
crontab is the command used to install, deinstall or list the tables (cron configuration file) used to drive the cron daemon in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

Different Types of cron Configuration

There are two different types of configuration files:
  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.
  2. The user crontabs: User can installer their own jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab

How Do I Install / Create / Edit My Own Cronjobs?

To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e

Syntax of crontab (Field Description)

Your cron job looks as follows for user jobs:
 
1 2 3 4 5 /path/to/command arg1 arg2
 
OR
 
1 2 3 4 5 /root/backup.sh
 
Where,
  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])
  • /path/to/command - Script or command name to schedule
Easy to remember format:
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
Your cron job looks as follows for system jobs:
1 2 3 4 5 USERNAME /path/to/command arg1 arg2
OR
1 2 3 4 5 USERNAME /path/to/script.sh

Example: Install Backup Job Script

If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e

Append the following entry:
0 3 * * * /root/backup.sh

Save and close the file.

More Examples

To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command

Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh

Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php

Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl

Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand

How Do I Use Operators?

An operator allows you to specifying multiple values in a field. There are three operators:
  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
  2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".
  3. The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,....,13,14,15" using the comma operator.

How Do I Disable Email Output?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1

To mail output to particular email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1

Task: List All Your crontab Jobs

Type the following command :
# crontab -l
# crontab -u username -l

To remove or erase all crontab jobs use the following command:
# crontab -r
crontab -r -u username

Use special string to save time

Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.
Special string Meaning
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
Run ntpdate every hour:
@hourly /path/to/ntpdate

Make a backup everyday:
@daily /path/to/backup/script.sh

Understanding /etc/crontab file and /etc/cron.d/* directories

/etc/crontab is system crontabs file. Usually only used by root user or daemons to configure system wide jobs. All individual user must must use crontab command to install and edit their jobs as described above. /var/spool/cron/ or /var/cron/tabs/ is directory for personal user crontab files. It must be backup with users home directory.

Understanding Default /etc/crontab

Typical /etc/crontab file entries:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
First, the environment must be defined. If the shell line is omitted, cron will use the default, which is sh. If the PATH variable is omitted, no default will be used and file locations will need to be absolute. If HOME is omitted, cron will use the invoking users home directory.
(3)
Additionally, cron reads the files in /etc/cron.d/ directory. Usually system daemon such as sa-update or sysstat places their cronjob here. As a root user or superuser you can use following directories to configure cronjobs. You can directly drop your scripts here. run-parts command run scripts or programs in a directory via /etc/crontab
Directory Description
/etc/cron.d/ Put all scripts here and call them from /etc/crontab file.
/etc/cron.daily/ Run all scripts once a day
/etc/cron.hourly/ Run all scripts once an hour
/etc/cron.monthly/ Run all scripts once a month
/etc/cron.weekly/ Run all scripts once a week

How do I Use Above Directories To Put My Scripts?

Here is a sample shell script (clean.cache) to clean up cached files every 10 days. This script is directly created at /etc/cron.daliy/ directory i.e. create a file called /etc/cron.daily/clean.cache:
 #!/bin/bash
# A sample shell script to clean cached file from lighttpd web server
CROOT="/tmp/cachelighttpd/"
DAYS=10
LUSER="lighttpd"
LGROUP="lighttpd"
 
# start cleaning
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm
 
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
        /bin/mkdir -p $CROOT
        /bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi

How Do I Backup Installed Cronjobs Entries?

Simply type the following command to backup your cronjobs to a nas server mounted at /nas01/backup/cron/users.root.bakup directory:
# crontab -l > /nas01/backup/cron/users.root.bakup
# crontab -u userName -l > /nas01/backup/cron/users.userName.bakup