*************************************************
To drop all ping packets all together
*************************************************
You can setup kernel variable to drop all ping packets.
# echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
This instructs the kernel to simply ignore all ping requests (ICMP type 0 messages).
To enable ping request type the command:
# echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
[or]
You can drop by adding following line to /etc/sysctl.conf file:
net.ipv4.icmp_echo_ignore_all = 1
Save and close the file.
Saturday, May 28, 2011
Monday, May 23, 2011
To Find The Details Of The CPU
To Find The Details Of The CPU , Instead Of Opening The File cat /etc/cpuinfo
# dmidecode -t type
Type Information
----------------------------------------
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
# dmidecode -t type
Type Information
----------------------------------------
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
Thursday, May 19, 2011
Linux Ext2,Ext3,Ext4 File systems
A LINUX file system is a collection of files and directories stored. Each file system is stored in a separate whole disk partition.here we see file system types
The ext2 (second extended file system) is a file system for the Linux kernel. It was initially designed by Remy Card as a replacement for the extended file system (ext).It was introduced with the 1.0 kernel in 1993.Ext2 is flexible,can handle file system up to 4 TB,and supports long file names up to 1012 characters,it has sparse super blocks feature which increase file system performance.In case any user processes fill up a file system,ext2 normally reserves about 5% of disk blocks for exclusive use by root so that root can easily recover from that situation.
The ext3 (third extended file system) is a journal ed file system that is commonly used by the Linux kernel. It is the default file system for many popular Linux distributions,Stephen Tweedie developed ext3.It provides all the features of ext2,and also features journaling and backward compatibility with ext2.The backward compatibility enables you to still run kernels that are only ext2-aware with ext3 partitions.we can also use all of the ext2 file system tuning,repair and recovery tools with ext3 also you can upgrade an ext2 file system to an ext3 file system without losing any of your data.
Ext3’s journaling feature speeds up the amount of time ,in ext2 when a file system is uncleanly mounted ,the whole file system must be checked.This takes a long time on large file systems.On an ext3 system ,the system keeps a record of uncommitted file transactions and applies only those transactions when the system is brought back up.So a complete system check is not required and the system will come back up much faster.
The ext4 (fourth extended file system) is a journaling file system for Linux,Ext4 is part of the Linux 2.6.28 kernel,Ext4 is the evolution of the most used Linux file system, Ext3. In many ways, Ext4 is a deeper improvement over Ext3 than Ext3 was over Ext2. Ext3 was mostly about adding journaling to Ext2, but Ext4 modifies important data structures of the file system such as the ones destined to store the file data. The result is a filesystem with an improved design, better performance, reliability and features.developed by Mingming Cao,Andreas Dilger,Alex Zhuravlev,Dave Kleikamp,Theodore Ts'o, Eric Sandeen,Sam Naghshineh and others.
The ext2 (second extended file system) is a file system for the Linux kernel. It was initially designed by Remy Card as a replacement for the extended file system (ext).It was introduced with the 1.0 kernel in 1993.Ext2 is flexible,can handle file system up to 4 TB,and supports long file names up to 1012 characters,it has sparse super blocks feature which increase file system performance.In case any user processes fill up a file system,ext2 normally reserves about 5% of disk blocks for exclusive use by root so that root can easily recover from that situation.
The ext3 (third extended file system) is a journal ed file system that is commonly used by the Linux kernel. It is the default file system for many popular Linux distributions,Stephen Tweedie developed ext3.It provides all the features of ext2,and also features journaling and backward compatibility with ext2.The backward compatibility enables you to still run kernels that are only ext2-aware with ext3 partitions.we can also use all of the ext2 file system tuning,repair and recovery tools with ext3 also you can upgrade an ext2 file system to an ext3 file system without losing any of your data.
Ext3’s journaling feature speeds up the amount of time ,in ext2 when a file system is uncleanly mounted ,the whole file system must be checked.This takes a long time on large file systems.On an ext3 system ,the system keeps a record of uncommitted file transactions and applies only those transactions when the system is brought back up.So a complete system check is not required and the system will come back up much faster.
The ext4 (fourth extended file system) is a journaling file system for Linux,Ext4 is part of the Linux 2.6.28 kernel,Ext4 is the evolution of the most used Linux file system, Ext3. In many ways, Ext4 is a deeper improvement over Ext3 than Ext3 was over Ext2. Ext3 was mostly about adding journaling to Ext2, but Ext4 modifies important data structures of the file system such as the ones destined to store the file data. The result is a filesystem with an improved design, better performance, reliability and features.developed by Mingming Cao,Andreas Dilger,Alex Zhuravlev,Dave Kleikamp,Theodore Ts'o, Eric Sandeen,Sam Naghshineh and others.
Tuesday, May 17, 2011
To Clear Linux Memory Cache
To free pagecache:
# sync; echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# sync; echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
# sync; echo 3 > /proc/sys/vm/drop_caches
==> sync - flush file system buffers
# sync; echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# sync; echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
# sync; echo 3 > /proc/sys/vm/drop_caches
==> sync - flush file system buffers
Monday, May 16, 2011
File Fragmentation checking on Linux
To find file fragmentation information for a specific file,we can use filefrag command.
filefrag reports on how badly fragmented a particular file. It makes allowances for indirect blocks for ext2 and ext3 filesystems, but can be used on files for any filesystem.
syntax:
filefrag -v (filename)
# filefrag -v /home/example/example.txt
-v => verbose when checking for file fragmentation
ouptput:(for example)
Checking example.txt
Filesystem type is: ef53
Filesystem cylinder groups is approximately 606
Blocksize of file example.txt is 4096
File size of example.txt is 1194 (1 blocks)
First block: 7006588
Last block: 7006588
example.txt: 1 extent found
filefrag reports on how badly fragmented a particular file. It makes allowances for indirect blocks for ext2 and ext3 filesystems, but can be used on files for any filesystem.
syntax:
filefrag -v (filename)
# filefrag -v /home/example/example.txt
-v => verbose when checking for file fragmentation
ouptput:(for example)
Checking example.txt
Filesystem type is: ef53
Filesystem cylinder groups is approximately 606
Blocksize of file example.txt is 4096
File size of example.txt is 1194 (1 blocks)
First block: 7006588
Last block: 7006588
example.txt: 1 extent found
Wednesday, May 4, 2011
Command to check UUID
In your /etc/fstab file, you have have seen an entry that looks UUID=c81355eb-96d2-458a-8ce0-3fa12a04cb8e instead of a more familiar disk drive designation, such as /dev/hda1. Such entries are called universally unique identifiers (UUID). You can use these 128-bit numbers to make hard disk management easier.
This following command is used to print the UUID for a device. This may be used with UUID= in /etc/fstab to name devices that works even if disks are added and removed. redhat uses this in /etc/fstab file.
Print UUID to a selected partition /dev/sda1
#blkid -o value -s UUID /dev/sda1
Print all UUIDs
#blkid -o value -s UUID
This following command is used to print the UUID for a device. This may be used with UUID= in /etc/fstab to name devices that works even if disks are added and removed. redhat uses this in /etc/fstab file.
Print UUID to a selected partition /dev/sda1
#blkid -o value -s UUID /dev/sda1
Print all UUIDs
#blkid -o value -s UUID
Tuesday, May 3, 2011
Strange Linux Commands Stands For
awk = "Aho Weinberger and Kernighan"
This language was named by its authors, Al Aho, Peter Weinberger and Brian Kernighan.
cat = "CATenate"
The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.
grep = "Global Regular Expression Print"
grep comes from the ed command to print all lines matching a certain pattern g/re/p where re is a regular expression.
fgrep = "Fixed GREP"
fgrep searches for fixed strings only. The "f" does not stand for "fast" - in fact, "fgrep foobar *.c" is usually slower than "egrep foobar *.c"
egrep = "Extended GREP"
nroff = "New ROFF"
troff = "Typesetter new ROFF"
These are descendants of "roff", which was a re-implementation of the Multics "runoff" program (a program that you'd use to "run off" a good copy of a document)
tee = T
From plumbing terminology for a T-shaped pipe splitter.
Perl = "Practical Extraction and Report Language"
Perl = "Pathologically Eclectic Rubbish Lister"
The Perl language is Larry Wall's highly popular freely-available completely portable text, process, and file manipulation tool that bridges the gap between shell and C programming.
This language was named by its authors, Al Aho, Peter Weinberger and Brian Kernighan.
cat = "CATenate"
The cat command is a standard Unix program used to concatenate and display files. The name is from catenate, a synonym of concatenate.
grep = "Global Regular Expression Print"
grep comes from the ed command to print all lines matching a certain pattern g/re/p where re is a regular expression.
fgrep = "Fixed GREP"
fgrep searches for fixed strings only. The "f" does not stand for "fast" - in fact, "fgrep foobar *.c" is usually slower than "egrep foobar *.c"
egrep = "Extended GREP"
nroff = "New ROFF"
troff = "Typesetter new ROFF"
These are descendants of "roff", which was a re-implementation of the Multics "runoff" program (a program that you'd use to "run off" a good copy of a document)
tee = T
From plumbing terminology for a T-shaped pipe splitter.
Perl = "Practical Extraction and Report Language"
Perl = "Pathologically Eclectic Rubbish Lister"
The Perl language is Larry Wall's highly popular freely-available completely portable text, process, and file manipulation tool that bridges the gap between shell and C programming.
Friday, April 29, 2011
To watch SSH users actions
To view your ssh user activities
#cat /dev/vcs1
this will show you what happens in first console. to check other consoles /dev/vcs1 or vcs2 or vcs3.
#cat /dev/vcs1
this will show you what happens in first console. to check other consoles /dev/vcs1 or vcs2 or vcs3.
To find IP address & To watch Linux Memory usage
Find out your router’s external IP address using the Linux command line
To Find Router external IP.Using the following commands we can see our router external IP address
without curl
#wget -O - -q icanhazip.com
with curl
#curl ifconfig.me
#curl icanhazip.com
#curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
TO see Linux memory usage in real-time
If you want to display your memory usage in real-time, do a
#watch -d "free -mt"
It will display used and free memory every two seconds.
To Find Router external IP.Using the following commands we can see our router external IP address
without curl
#wget -O - -q icanhazip.com
with curl
#curl ifconfig.me
#curl icanhazip.com
#curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
TO see Linux memory usage in real-time
If you want to display your memory usage in real-time, do a
#watch -d "free -mt"
It will display used and free memory every two seconds.
Wednesday, April 27, 2011
Linux Command For Gmail inbox checking
To check the gmail,u can access ur gmail inbox from command prompt.
#curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'
#curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /
Wednesday, April 20, 2011
Few Error Logs and solutions
Template Error: The template file must be given
Error : Template Error: The template file must be given
Solution : The problem due the cpanel default page missing on the server so you can reset the default page setting by using following steps …
WHM Main >> Account Functions >> Web Template Editor > Revert to Default
Once done you will again see the cpanel default page.
If you are facing this error on number of domains then you need to add the apache conf entry for that domain manually into httpd.conf file.
Manager of pid-file quit without updating fi
Error : Manager of pid-file quit without updating fi
Solution : When try to restart the mysql service on the server then above error is generated.
This problem is occurred due the “mysql ” database crashed and should be repaired but the mysql is already stopped on the server so you need to use the following command to repair and optimize the database when mysql service is down on the server.
For Repair “mysql ” database
# find /var/lib/mysql/mysql -name '*.MYI' -exec myisamchk -r {} \;
For Optimize the database
# find /var/lib/mysql -name '*.MYI' -exec myisamchk -o {} \;
Then
# ps -ef | grep mysql
# killall -KILL mysql
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
DB Error: connect failed in horde
Error : When try to access the Horde from cPanel then it shows following error.
Warning: fopen(/var/cpanel/horde/log/horde_0.log) [function.fopen]: failed to open stream: Permission denied in /usr/local/cpanel/3rdparty/lib/php/Log/file.php on line 216
A fatal error has occurred
DB Error: connect failed
Details have been logged for the administrator.
Solution: The problem due to the ” Horde Groupware Webmail Edition detected ” means when you have try to update the Horde by using following commands
root@server[~]# /usr/local/cpanel/bin/update-horde --force
Then it shows the following error
!!! Horde Groupware Webmail Edition detected !!!
Install or update of standard Horde Webmail is disabled.
Horde Groupware Webmail was installed with cPanel 11.25.1.
Downgrades of Horde are not permitted due to MySQL differences.
Then you need to move the file
root@server[~]# mv /var/cpanel/horde/groupware_version /var/cpanel/horde/groupware_version-bak
After that run following commands
root@server[~]# /usr/local/cpanel/bin/update-horde --force
Request exceeded the limit of 10 internal redirects
Error : Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace
Solution : When access the domain and the domain not shows the content and the server logs shows the above error then you need to add the following code in .htaccess file.
RewriteCond %{ENV:REDIRECT_STATUS} 200
Or
If you are facing this problem for the addon domain then add the following Rewrite rules in main domain .htaccess file.
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
Rewriterule .* – [L]
Error : Template Error: The template file must be given
Solution : The problem due the cpanel default page missing on the server so you can reset the default page setting by using following steps …
WHM Main >> Account Functions >> Web Template Editor > Revert to Default
Once done you will again see the cpanel default page.
If you are facing this error on number of domains then you need to add the apache conf entry for that domain manually into httpd.conf file.
Manager of pid-file quit without updating fi
Error : Manager of pid-file quit without updating fi
Solution : When try to restart the mysql service on the server then above error is generated.
This problem is occurred due the “mysql ” database crashed and should be repaired but the mysql is already stopped on the server so you need to use the following command to repair and optimize the database when mysql service is down on the server.
For Repair “mysql ” database
# find /var/lib/mysql/mysql -name '*.MYI' -exec myisamchk -r {} \;
For Optimize the database
# find /var/lib/mysql -name '*.MYI' -exec myisamchk -o {} \;
Then
# ps -ef | grep mysql
# killall -KILL mysql
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
DB Error: connect failed in horde
Error : When try to access the Horde from cPanel then it shows following error.
Warning: fopen(/var/cpanel/horde/log/horde_0.log) [function.fopen]: failed to open stream: Permission denied in /usr/local/cpanel/3rdparty/lib/php/Log/file.php on line 216
A fatal error has occurred
DB Error: connect failed
Details have been logged for the administrator.
Solution: The problem due to the ” Horde Groupware Webmail Edition detected ” means when you have try to update the Horde by using following commands
root@server[~]# /usr/local/cpanel/bin/update-horde --force
Then it shows the following error
!!! Horde Groupware Webmail Edition detected !!!
Install or update of standard Horde Webmail is disabled.
Horde Groupware Webmail was installed with cPanel 11.25.1.
Downgrades of Horde are not permitted due to MySQL differences.
Then you need to move the file
root@server[~]# mv /var/cpanel/horde/groupware_version /var/cpanel/horde/groupware_version-bak
After that run following commands
root@server[~]# /usr/local/cpanel/bin/update-horde --force
Request exceeded the limit of 10 internal redirects
Error : Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace
Solution : When access the domain and the domain not shows the content and the server logs shows the above error then you need to add the following code in .htaccess file.
RewriteCond %{ENV:REDIRECT_STATUS} 200
Or
If you are facing this problem for the addon domain then add the following Rewrite rules in main domain .htaccess file.
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
Rewriterule .* – [L]
Crontab - 15 Cron Job Examples
An experienced Linux sysadmin knows the importance of running the routine maintenance jobs in the background automatically.
Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Table: Crontab Fields and Allowed Ranges (Linux Crontab Syntax)Field Description Allowed Value
MIN Minute field 0 to 59
HOUR Hour field 0 to 23
DOM Day of Month 1-31
MON Month field 1-12
DOW Day Of Week 0-6
CMD Command Any command to be executed.
1. Scheduling a Job For a Specific Time Every Day
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/raj/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
2. Schedule a Job For More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.
This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.
00 11,16 * * * /home/raj/bin/incremental-backup
00 – 0th Minute (Top of the hour)
11,16 – 11 AM and 4 PM
* – Every day
* – Every month
* – Every day of the week
3. Schedule a Job for Specific Range of Time (e.g. Only on Weekdays)
If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/raj/bin/checkdatabase
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
* – Every day of the week
Cron Job every weekday during working hours
This example checks the status of the database every weekday (i.e excluding Sat and Sun) during the working hours 9 a.m – 6 p.m.
4. How to View Crontab Entries?
View Current Logged-In User’s Crontab entries
To view your crontab entries type crontab -l from your unix account as shown below.
raj@mail$ crontab -l
0-55/5 * * * * /usr/sbin/vnstat.cron
[Note: This displays crontab of the current logged in user]
View Root Crontab entries
Login as root user (su – root) and do crontab -l as shown below.
root@mail# crontab -l
no crontab for root
Crontab HowTo: View Other Linux User’s Crontabs entries
To view crontab entries of other Linux users, login to root and use -u {username} -l as shown below.
root@mail# crontab -u raj -l
00 09-18 * * * /home/raj/checkdatabase
5. How to Edit Crontab Entries?
Edit Current Logged-In User’s Crontab entries
To edit a crontab entries, use crontab -e as shown below. By default this will edit the current logged-in users crontab.
raj@mail$ crontab -e
*/10 * * * * /home/raj/debian/bin/check-disk-space
~
"/tmp/crontab.XXXXyjWkHw" 2L, 83C
[Note: This will open the crontab file in Vim editor for editing.
Please note cron created a temporary /tmp/crontab.XX... ]
When you save the above temporary file with :wq, it will save the crontab and display the following message indicating the crontab is successfully modified.
~
"crontab.XXXXyjWkHw" 2L, 83C written
crontab: installing new crontab
Edit Root Crontab entries
Login as root user (su – root) and do crontab -e as shown below.
root@mail# crontab -e
Edit Other Linux User’s Crontab File entries
To edit crontab entries of other Linux users, login to root and use -u {username} -e as shown below.
root@mail# crontab -u raj -e
00 09-18 * * * /home/raj/ubuntu/bin/check-db-status
~
~
~
"/tmp/crontab.XXXXyjWkHw" 2L, 83C
6. Schedule a Job for Every Minute Using Cron.
Ideally you may not have a requirement to schedule a job every minute. But understanding this example will will help you understand the other examples mentioned below in this article.
* * * * * CMD
The * means all the possible unit — i.e every minute of every hour through out the year. More than using this * directly, you will find it very useful in the following cases.
When you specify */5 in minute field means every 5 minutes.
When you specify 0-10/2 in minute field mean every 2 minutes in the first 10 minute.
Thus the above convention can be used for all the other 4 fields.
7. Schedule a Background Cron Job For Every 10 Minutes.
Use the following, if you want to check the disk space every 10 minutes.
*/10 * * * * /home/raj/check-disk-space
It executes the specified command check-disk-space every 10 minutes through out the year. But you may have a requirement of executing the command only during office hours or vice versa. The above examples shows how to do those things.
Instead of specifying values in the 5 fields, we can specify it using a single keyword as mentioned below.
There are special cases in which instead of the above 5 fields you can use @ followed by a keyword — such as reboot, midnight, yearly, hourly.
Table: Cron special keywords and its meaningKeyword Equivalent
@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot Run at startup.
8. Schedule a Job For First Minute of Every Year using @yearly
If you want a job to be executed on the first minute of every year, then you can use the @yearly cron keyword as shown below.
This will execute the system annual maintenance using annual-maintenance shell script at 00:00 on Jan 1st for every year.
@yearly /home/raj/red-hat/bin/annual-maintenance
9. Schedule a Cron Job Beginning of Every Month using @monthly
It is as similar as the @yearly as above. But executes the command monthly once using @monthly cron keyword.
This will execute the shell script tape-backup at 00:00 on 1st of every month.
@monthly /home/raj/suse/bin/tape-backup
10. Schedule a Background Job Every Day using @daily
Using the @daily cron keyword, this will do a daily log file cleanup using cleanup-logs shell scriptat 00:00 on every day.
@daily /home/raj/arch-linux/bin/cleanup-logs "day started"
11. How to Execute a Linux Command After Every Reboot using @reboot?
Using the @reboot cron keyword, this will execute the specified command once after the machine got booted every time.
@reboot CMD
12. How to Disable/Redirect the Crontab Mail Output using MAIL keyword?
By default crontab sends the job output to the user who scheduled the job. If you want to redirect the output to a specific user, add or update the MAIL variable in the crontab as shown below.
raj@mail$ crontab -l
MAIL="raj"
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/raj/check-disk-space
[Note: Crontab of the current logged in user with MAIL variable]
If you wanted the mail not to be sent to anywhere, i.e to stop the crontab output to be emailed, add or update the MAIL variable in the crontab as shown below.
MAIL=""
13. How to Execute a Linux Cron Jobs Every Second Using Crontab.
You cannot schedule a every-second cronjob. Because in cron the minimum unit you can specify is minute. In a typical scenario, there is no reason for most of us to run any job every second in the system.
14. Specify PATH Variable in the Crontab
All the above examples we specified absolute path of the Linux command or the shell-script that needs to be executed.
For example, instead of specifying /home/raj/tape-backup, if you want to just specify tape-backup, then add the path /home/raj to the PATH variable in the crontab as shown below.
raj@mail$ crontab -l
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/raj
@yearly annual-maintenance
*/10 * * * * check-disk-space
[Note: Crontab of the current logged in user with PATH variable]
15. Installing Crontab From a Cron File
Instead of directly editing the crontab file, you can also add all the entries to a cron-file first. Once you have all thoese entries in the file, you can upload or install them to the cron as shown below.
raj@mail$ crontab -l
no crontab for ramesh
$ cat cron-file.txt
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/ramej/check-disk-space
raj@mail$ crontab cron-file.txt
raj@mail$ crontab -l
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/raj/check-disk-space
Note: This will install the cron-file.txt to your crontab, which will also remove your old cron entries. So, please be careful while uploading cron entries from a cron-file.txt.
Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Table: Crontab Fields and Allowed Ranges (Linux Crontab Syntax)Field Description Allowed Value
MIN Minute field 0 to 59
HOUR Hour field 0 to 23
DOM Day of Month 1-31
MON Month field 1-12
DOW Day Of Week 0-6
CMD Command Any command to be executed.
1. Scheduling a Job For a Specific Time Every Day
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/raj/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
2. Schedule a Job For More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.
This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.
00 11,16 * * * /home/raj/bin/incremental-backup
00 – 0th Minute (Top of the hour)
11,16 – 11 AM and 4 PM
* – Every day
* – Every month
* – Every day of the week
3. Schedule a Job for Specific Range of Time (e.g. Only on Weekdays)
If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/raj/bin/checkdatabase
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
* – Every day of the week
Cron Job every weekday during working hours
This example checks the status of the database every weekday (i.e excluding Sat and Sun) during the working hours 9 a.m – 6 p.m.
4. How to View Crontab Entries?
View Current Logged-In User’s Crontab entries
To view your crontab entries type crontab -l from your unix account as shown below.
raj@mail$ crontab -l
0-55/5 * * * * /usr/sbin/vnstat.cron
[Note: This displays crontab of the current logged in user]
View Root Crontab entries
Login as root user (su – root) and do crontab -l as shown below.
root@mail# crontab -l
no crontab for root
Crontab HowTo: View Other Linux User’s Crontabs entries
To view crontab entries of other Linux users, login to root and use -u {username} -l as shown below.
root@mail# crontab -u raj -l
00 09-18 * * * /home/raj/checkdatabase
5. How to Edit Crontab Entries?
Edit Current Logged-In User’s Crontab entries
To edit a crontab entries, use crontab -e as shown below. By default this will edit the current logged-in users crontab.
raj@mail$ crontab -e
*/10 * * * * /home/raj/debian/bin/check-disk-space
~
"/tmp/crontab.XXXXyjWkHw" 2L, 83C
[Note: This will open the crontab file in Vim editor for editing.
Please note cron created a temporary /tmp/crontab.XX... ]
When you save the above temporary file with :wq, it will save the crontab and display the following message indicating the crontab is successfully modified.
~
"crontab.XXXXyjWkHw" 2L, 83C written
crontab: installing new crontab
Edit Root Crontab entries
Login as root user (su – root) and do crontab -e as shown below.
root@mail# crontab -e
Edit Other Linux User’s Crontab File entries
To edit crontab entries of other Linux users, login to root and use -u {username} -e as shown below.
root@mail# crontab -u raj -e
00 09-18 * * * /home/raj/ubuntu/bin/check-db-status
~
~
~
"/tmp/crontab.XXXXyjWkHw" 2L, 83C
6. Schedule a Job for Every Minute Using Cron.
Ideally you may not have a requirement to schedule a job every minute. But understanding this example will will help you understand the other examples mentioned below in this article.
* * * * * CMD
The * means all the possible unit — i.e every minute of every hour through out the year. More than using this * directly, you will find it very useful in the following cases.
When you specify */5 in minute field means every 5 minutes.
When you specify 0-10/2 in minute field mean every 2 minutes in the first 10 minute.
Thus the above convention can be used for all the other 4 fields.
7. Schedule a Background Cron Job For Every 10 Minutes.
Use the following, if you want to check the disk space every 10 minutes.
*/10 * * * * /home/raj/check-disk-space
It executes the specified command check-disk-space every 10 minutes through out the year. But you may have a requirement of executing the command only during office hours or vice versa. The above examples shows how to do those things.
Instead of specifying values in the 5 fields, we can specify it using a single keyword as mentioned below.
There are special cases in which instead of the above 5 fields you can use @ followed by a keyword — such as reboot, midnight, yearly, hourly.
Table: Cron special keywords and its meaningKeyword Equivalent
@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot Run at startup.
8. Schedule a Job For First Minute of Every Year using @yearly
If you want a job to be executed on the first minute of every year, then you can use the @yearly cron keyword as shown below.
This will execute the system annual maintenance using annual-maintenance shell script at 00:00 on Jan 1st for every year.
@yearly /home/raj/red-hat/bin/annual-maintenance
9. Schedule a Cron Job Beginning of Every Month using @monthly
It is as similar as the @yearly as above. But executes the command monthly once using @monthly cron keyword.
This will execute the shell script tape-backup at 00:00 on 1st of every month.
@monthly /home/raj/suse/bin/tape-backup
10. Schedule a Background Job Every Day using @daily
Using the @daily cron keyword, this will do a daily log file cleanup using cleanup-logs shell scriptat 00:00 on every day.
@daily /home/raj/arch-linux/bin/cleanup-logs "day started"
11. How to Execute a Linux Command After Every Reboot using @reboot?
Using the @reboot cron keyword, this will execute the specified command once after the machine got booted every time.
@reboot CMD
12. How to Disable/Redirect the Crontab Mail Output using MAIL keyword?
By default crontab sends the job output to the user who scheduled the job. If you want to redirect the output to a specific user, add or update the MAIL variable in the crontab as shown below.
raj@mail$ crontab -l
MAIL="raj"
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/raj/check-disk-space
[Note: Crontab of the current logged in user with MAIL variable]
If you wanted the mail not to be sent to anywhere, i.e to stop the crontab output to be emailed, add or update the MAIL variable in the crontab as shown below.
MAIL=""
13. How to Execute a Linux Cron Jobs Every Second Using Crontab.
You cannot schedule a every-second cronjob. Because in cron the minimum unit you can specify is minute. In a typical scenario, there is no reason for most of us to run any job every second in the system.
14. Specify PATH Variable in the Crontab
All the above examples we specified absolute path of the Linux command or the shell-script that needs to be executed.
For example, instead of specifying /home/raj/tape-backup, if you want to just specify tape-backup, then add the path /home/raj to the PATH variable in the crontab as shown below.
raj@mail$ crontab -l
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/raj
@yearly annual-maintenance
*/10 * * * * check-disk-space
[Note: Crontab of the current logged in user with PATH variable]
15. Installing Crontab From a Cron File
Instead of directly editing the crontab file, you can also add all the entries to a cron-file first. Once you have all thoese entries in the file, you can upload or install them to the cron as shown below.
raj@mail$ crontab -l
no crontab for ramesh
$ cat cron-file.txt
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/ramej/check-disk-space
raj@mail$ crontab cron-file.txt
raj@mail$ crontab -l
@yearly /home/raj/annual-maintenance
*/10 * * * * /home/raj/check-disk-space
Note: This will install the cron-file.txt to your crontab, which will also remove your old cron entries. So, please be careful while uploading cron entries from a cron-file.txt.
Saturday, April 16, 2011
லினக்ஸ் வரலாறு
க்னூ/லினக்ஸ் (GNU/Linux) என்பது கணினிகளில் உள்ள ஓர் இயக்குதளமாகும்..
இவ்வியக்குதளம் பொதுவாக லினக்ஸ் என்ற பெயரால் அறியப்படுகிறது. ஆனாலும், இதன் மிகச்சரியான நிறுவன ஏற்புப் (உத்தியோகபூர்வமான) பெயர் க்னூ/லினக்ஸ் என்பதேயாகும்.
* 1983: ரிச்சர்ட் ஸ்டால்மன் அவர்களால் க்னூ திட்டம் தொடங்கப்படுகிறது. இத்திட்டம் யுனிக்ஸ்">யுனிக்ஸ் இயக்குதளத்தை ஒத்த திறந்த ஆணைமூல இயக்குதளம் ஒன்றினை உருவாக்குதலை நோக்கமாக கொண்டிருந்தது.
* 1990: க்னூ செயல் திட்டம் ஏறத்தாழ நிறைவடையும் நிலையை அண்மித்தது. ஓர் இயக்குதளத்துக்கு தேவையான செயலிகள் (இன்னமும் எழுதப்படவில்லை)">செயலிகள், காம்பைலர்கள், உரைத்தொகுப்பிகள், யுனிக்சை ஒத்த ஆணைமுகப்பு (command shell) போன்றவை அனைத்தும் செய்து முடிக்கப்பட்டுவிட்டன. மிக அடிப்படை நிலையில் இருக்கும் கரு (கருனி) ( kernel) ஒன்றை உருவாக்கும் பணி மட்டுமே முற்றுப்பெறவில்லை. அப்போது GNU Hurd என்ற கரு (கருனி) வடிவமைக்கப்பட்ட வண்ணமிருந்தாலும், அது போதாததாகவே உணரப்பட்டது.
* 1991: லினக்ஸ் ஸ்டோவாட்ஸ் என்பவர், அக்காலத்தில் அவருக்கு பல்கலைக்கழகத்தில் கற்பித்த பேராசிரியர், இயங்குதளங்களை பற்றி கற்பிப்பதற்காக வடிவமைத்து வைத்திருந்த மினிக்ஸ் (இன்னமும் எழுதப்படவில்லை)">மினிக்ஸ் என்ற மென்பொருளை மேம்படுத்த முயன்றுகொண்டிருந்தார். இதற்கான அனுமதி மறுக்கப்படவே, மினிக்சை ஒத்த இயக்குதளம் ஒன்றை வடிவமைக்கத் தொடங்கினார். இதன் படிவளர்ச்சி நாளடைவில் ஒரு முழுமையான இயக்குதள கருவைத் (கருனியைத்) தந்தளித்தது.
* 1991 செப்டெம்பர் 17: லினக்ஸ் தனது இயங்குதளத்தை இணையத்தில் கிடைக்கச்செய்கிறார். இதன் ஆணைமூலத்தை பெற்ற ஏராளமான நிரலாளர்கள் (இன்னமும் எழுதப்படவில்லை)">நிரலாளர்கள் லினக்சை மேன்மேலும் வளர்த்தெடுக்கிறார்கள்.
அக்காலத்தில் லினக்சை செயற்படுத்த மினிக்ஸ் தொகுதி தேவைப்பட்டது. லினக்ஸ் கருவினை (கருனியை) செயற்படுத்த ஒரு சிறந்த இயக்குதளத்தின் தேவை உணரப்பட்ட நிலையில் லினக்ஸ்ஸும் அவருடன் பணியாற்றிய ஏனைய நிரலாளர்களும் க்னூ செயற்றிட்டத்தின் மென்பொருட்களுடன் லினக்சை ஒருங்கிணைப்பது என்ற முடிவுக்கு வந்தனர்.
இவ்வியக்குதளம் பொதுவாக லினக்ஸ் என்ற பெயரால் அறியப்படுகிறது. ஆனாலும், இதன் மிகச்சரியான நிறுவன ஏற்புப் (உத்தியோகபூர்வமான) பெயர் க்னூ/லினக்ஸ் என்பதேயாகும்.
* 1983: ரிச்சர்ட் ஸ்டால்மன் அவர்களால் க்னூ திட்டம் தொடங்கப்படுகிறது. இத்திட்டம் யுனிக்ஸ்">யுனிக்ஸ் இயக்குதளத்தை ஒத்த திறந்த ஆணைமூல இயக்குதளம் ஒன்றினை உருவாக்குதலை நோக்கமாக கொண்டிருந்தது.
* 1990: க்னூ செயல் திட்டம் ஏறத்தாழ நிறைவடையும் நிலையை அண்மித்தது. ஓர் இயக்குதளத்துக்கு தேவையான செயலிகள் (இன்னமும் எழுதப்படவில்லை)">செயலிகள், காம்பைலர்கள், உரைத்தொகுப்பிகள், யுனிக்சை ஒத்த ஆணைமுகப்பு (command shell) போன்றவை அனைத்தும் செய்து முடிக்கப்பட்டுவிட்டன. மிக அடிப்படை நிலையில் இருக்கும் கரு (கருனி) ( kernel) ஒன்றை உருவாக்கும் பணி மட்டுமே முற்றுப்பெறவில்லை. அப்போது GNU Hurd என்ற கரு (கருனி) வடிவமைக்கப்பட்ட வண்ணமிருந்தாலும், அது போதாததாகவே உணரப்பட்டது.
* 1991: லினக்ஸ் ஸ்டோவாட்ஸ் என்பவர், அக்காலத்தில் அவருக்கு பல்கலைக்கழகத்தில் கற்பித்த பேராசிரியர், இயங்குதளங்களை பற்றி கற்பிப்பதற்காக வடிவமைத்து வைத்திருந்த மினிக்ஸ் (இன்னமும் எழுதப்படவில்லை)">மினிக்ஸ் என்ற மென்பொருளை மேம்படுத்த முயன்றுகொண்டிருந்தார். இதற்கான அனுமதி மறுக்கப்படவே, மினிக்சை ஒத்த இயக்குதளம் ஒன்றை வடிவமைக்கத் தொடங்கினார். இதன் படிவளர்ச்சி நாளடைவில் ஒரு முழுமையான இயக்குதள கருவைத் (கருனியைத்) தந்தளித்தது.
* 1991 செப்டெம்பர் 17: லினக்ஸ் தனது இயங்குதளத்தை இணையத்தில் கிடைக்கச்செய்கிறார். இதன் ஆணைமூலத்தை பெற்ற ஏராளமான நிரலாளர்கள் (இன்னமும் எழுதப்படவில்லை)">நிரலாளர்கள் லினக்சை மேன்மேலும் வளர்த்தெடுக்கிறார்கள்.
அக்காலத்தில் லினக்சை செயற்படுத்த மினிக்ஸ் தொகுதி தேவைப்பட்டது. லினக்ஸ் கருவினை (கருனியை) செயற்படுத்த ஒரு சிறந்த இயக்குதளத்தின் தேவை உணரப்பட்ட நிலையில் லினக்ஸ்ஸும் அவருடன் பணியாற்றிய ஏனைய நிரலாளர்களும் க்னூ செயற்றிட்டத்தின் மென்பொருட்களுடன் லினக்சை ஒருங்கிணைப்பது என்ற முடிவுக்கு வந்தனர்.
Subscribe to:
Posts (Atom)