Cron
This file is an introduction to cron, it covers the basics of what cron does,
and how to use it.
What is cron?
Cron is the name of program that enables unix users to execute commands or
scripts (groups of commands) automatically at a specified time/date. It is
normally used for sys admin commands, like makewhatis, which builds a
search database for the man -k command, or for running a backup script,
but can be used for anything. A common use for it today is connecting to
the internet and downloading your email.
This file will look at Vixie Cron, a version of cron authored by Paul Vixie.
How to start Cron
Cron is a daemon, which means that it only needs to be started once, and will
lay dormant until it is required. A Web server is a daemon, it stays dormant
until it gets asked for a web page. The cron daemon, or crond, stays dormant
until a time specified in one of the config files, or crontabs.
On most Linux distributions crond is automatically installed and entered into
the start up scripts. To find out if it's running do the following:
cog@pingu $ ps aux | grep crond
root 311 0.0 0.7 1284 112 ? S Dec24 0:00 crond
cog 8606 4.0 2.6 1148 388 tty2 S 12:47 0:00 grep crond
The top line shows that crond is running, the bottom line is the search
we just run.
If it's not running then either you killed it since the last time you rebooted,
or it wasn't started.
To start it, just add the line crond to one of your start up scripts. The
process automatically goes into the back ground, so you don't have to force
it with &. Cron will be started next time you reboot. To run it without
rebooting, just type crond as root:
root@pingu # crond
With lots of daemons, (e.g. httpd and syslogd) they need to be restarted
after the config files have been changed so that the program has a chance
to reload them. Vixie Cron will automatically reload the files after they
have been edited with the crontab command. Some cron versions reload the
files every minute, and some require restarting, but Vixie Cron just loads
the files if they have changed.
Using cron
There are a few different ways to use cron (surprise, surprise).
In the /etc directory you will probably find some sub directories called
'cron.hourly', 'cron.daily', 'cron.weekly' and 'cron.monthly'. If you place
a script into one of those directories it will be run either hourly, daily,
weekly or monthly, depending on the name of the directory.
If you want more flexibility than this, you can edit a crontab (the name
for cron's config files). The main config file is normally /etc/crontab.
On a default RedHat install, the crontab will look something like this:
root@pingu # cat /etc/crontab
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
The first part is almost self explanatory; it sets the variables for cron.
SHELL is the 'shell' cron runs under. If unspecified, it will default to
the entry in the /etc/passwd file.
PATH contains the directories which will be in the search path for cron
e.g if you've got a program 'foo' in the directory /usr/cog/bin, it might
be worth adding /usr/cog/bin to the path, as it will stop you having to use
the full path to 'foo' every time you want to call it.
MAILTO is who gets mailed the output of each command. If a command cron is
running has output (e.g. status reports, or errors), cron will email the output
to whoever is specified in this variable. If no one if specified, then the
output will be mailed to the owner of the process that produced the output.
HOME is the home directory that is used for cron. If unspecified, it will
default to the entry in the /etc/passwd file.
Now for the more complicated second part of a crontab file.
An entry in cron is made up of a series of fields, much like the /etc/passwd
file is, but in the crontab they are separated by a space. There are normally
seven fields in one entry. The fields are:
minute hour dom month dow user cmd
minute This controls what minute of the hour the command will run on,
and is between '0' and '59'
hour This controls what hour the command will run on, and is specified in
the 24 hour clock, values must be between 0 and 23 (0 is midnight)
dom This is the Day of Month, that you want the command run on, e.g. to
run a command on the 19th of each month, the dom would be 19.
month This is the month a specified command will run on, it may be specified
numerically (0-12), or as the name of the month (e.g. May)
dow This is the Day of Week that you want a command to be run on, it can
also be numeric (0-7) or as the name of the day (e.g. sun).
user This is the user who runs the command.
cmd This is the command that you want run. This field may contain
multiple words or spaces.
If you don't wish to specify a value for a field, just place a * in the
field.
e.g.
01 * * * * root echo "This command is run at one min past every hour"
17 8 * * * root echo "This command is run daily at 8:17 am"
17 20 * * * root echo "This command is run daily at 8:17 pm"
00 4 * * 0 root echo "This command is run at 4 am every Sunday"
* 4 * * Sun root echo "So is this"
42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * root echo "This command is run hourly on the 19th of July"
Notes:
Under dow 0 and 7 are both Sunday.
If both the dom and dow are specified, the command will be executed when
either of the events happen.
e.g.
* 12 16 * Mon root cmd
Will run cmd at midday every Monday and every 16th, and will produce the
same result as both of these entries put together would:
* 12 16 * * root cmd
* 12 * * Mon root cmd
Vixie Cron also accepts lists in the fields. Lists can be in the form, 1,2,3
(meaning 1 and 2 and 3) or 1-3 (also meaning 1 and 2 and 3).
e.g.
59 11 * * 1,2,3,4,5 root backup.sh
Will run backup.sh at 11:59 Monday, Tuesday, Wednesday, Thursday and Friday,
as will:
59 11 * * 1-5 root backup.sh
Cron also supports 'step' values.
A value of */2 in the dom field would mean the command runs every two days
and likewise, */5 in the hours field would mean the command runs every
5 hours.
e.g.
* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh
*/15 9-17 * * * root connection.test
Will run connection.test every 15 mins between the hours or 9am and 5pm
Lists can also be combined with each other, or with steps:
* 12 1-15,17,20-25 * * root cmd
Will run cmd every midday between the 1st and the 15th as well as the 20th
and 25th (inclusive) and also on the 17th of every month.
* 12 10-16/2 * * root backup.sh
is the same as:
* 12 10,12,14,16 * * root backup.sh
When using the names of weekdays or months, it isn't case sensitive, but only
the first three letters should be used, e.g. Mon, sun or Mar, jul.
Comments are allowed in crontabs, but they must be preceded with a '#', and
must be on a line by them self.
Multiuser cron
As Unix is a multiuser OS, some of the apps have to be able to support
multiple users, cron is one of these. Each user can have their own crontab
file, which can be created/edited/removed by the command crontab. This
command creates an individual crontab file and although this is a text file,
as the /etc/crontab is, it shouldn't be edited directly. The crontab file is
often stored in /var/spool/cron/crontabs/ (Unix/Slackware/*BSD),
/var/spool/cron/ (RedHat) or /var/cron/tabs/ (SuSE),
but might be kept elsewhere depending on what Un*x flavor you're running.
To edit (or create) your crontab file, use the command crontab -e, and this
will load up the editor specified in the environment variables EDITOR or
VISUAL, to change the editor invoked on Bourne-compliant shells, try:
cog@pingu $ export EDITOR=vi
On C shells:
cog@pingu $ setenv EDITOR vi
You can of course substitute vi for the text editor of your choice.
Your own personal crontab follows exactly the same format as the main
/etc/crontab file does, except that you need not specify the MAILTO
variable, as this entry defaults to the process owner, so you would be mailed
the output anyway, but if you so wish, this variable can be specified.
You also need not have the user field in the crontab entries. e.g.
min hr dom month dow cmd
Once you have written your crontab file, and exited the editor, then it will
check the syntax of the file, and give you a chance to fix any errors.
If you want to write your crontab without using the crontab command, you can
write it in a normal text file, using your editor of choice, and then use the
crontab command to replace your current crontab with the file you just wrote.
e.g. if you wrote a crontab called cogs.cron.file, you would use the cmd
cog@pingu $ crontab cogs.cron.file
to replace your existing crontab with the one in cogs.cron.file.
You can use
cog@pingu $ crontab -l
to list your current crontab, and
cog@pingu $ crontab -r
will remove (i.e. delete) your current crontab.
Privileged users can also change other user's crontab with:
root@pingu # crontab -u
and then following it with either the name of a file to replace the
existing user's crontab, or one of the -e, -l or -r options.
According to the documentation the crontab command can be confused by the
su command, so if you running a su'ed shell, then it is recommended you
use the -u option anyway.
Controlling Access to cron
Cron has a built in feature of allowing you to specify who may, and who
may not use it. It does this by the use of /etc/cron.allow and /etc/cron.deny
files. These files work the same way as the allow/deny files for other
daemons do. To stop a user using cron, just put their name in cron.deny, to
allow a user put their name in the cron.allow. If you wanted to prevent all
users from using cron, you could add the line ALL to the cron.deny file:
root@pingu # echo ALL >>/etc/cron.deny
If you want user cog to be able to use cron, you would add the line cog
to the cron.allow file:
root@pingu # echo cog >>/etc/cron.allow
If there is neither a cron.allow nor a cron.deny file, then the use of cron
is unrestricted (i.e. every user can use it). If you were to put the name of
some users into the cron.allow file, without creating a cron.deny file, it
would have the same effect as creating a cron.deny file with ALL in it.
This means that any subsequent users that require cron access should be
put in to the cron.allow file.
Output from cron
As I've said before, the output from cron gets mailed to the owner of the
process, or the person specified in the MAILTO variable, but what if you
don't want that? If you want to mail the output to someone else, you can
just pipe the output to the command mail.
e.g.
cmd | mail -s "Subject of mail" user
If you wish to mail the output to someone not located on the machine, in the
above example, substitute user for the email address of the person who
wishes to receive the output.
If you have a command that is run often, and you don't want to be emailed
the output every time, you can redirect the output to a log file (or
/dev/null, if you really don't want the output).
e,g
cmd >> log.file
Notice we're using two > signs so that the output appends the log file and
doesn't clobber previous output.
The above example only redirects the standard output, not the standard error,
if you want all output stored in the log file, this should do the trick:
cmd >> logfile 2>&1
You can then set up a cron job that mails you the contents of the file at
specified time intervals, using the cmd:
mail -s "logfile for cmd"
Now you should be able to use cron to automate things a bit more.
A future file going into more detail, explaining the differences between
the various different crons and with more worked examples, is planned.
Friday, March 11, 2011
Cron :: What is Cron ? Linux / Unix
Monday, January 17, 2011
Mod_Dosevasive in Apache
What Is Mod_Dosevasive?
An additional capability of the module is that it is also able to execute system commands when DoS attacks are identified. This provides an interface to send attacking IP addresses to other security applications such as local host-based firewalls to block the offending IP address. Mod_Dosevasive performs well in both single-server attacks, as well as distributed attacks; however, as with any DoS attack, the real concern is network bandwidth and processor/ RAM usage.
How Does Mod_Dosevasive Work?
Mod_Dosevasive identifies attacks by creating and using an internal dynamic hash table of IP Addresses to URIs pairs based on the requests received. When a new request comes into Apache, Mod_Dosevasive will perform the following tasks:- The IP address of the client is checked in the temporary blacklist of the hash table. If the IP address is listed, then the client is denied access with a 403 Forbidden.
- If the client is not currently on the blacklist, then the IP address of the client and the Universal Resource Identifier (URI) being requested are hashed into a key. Mod_Dosevasive will then check the listener's hash table to verify if any of the same hashes exist. If it does, it will then evaluate the total number of matched hashes and the timeframe that they were requested in versus the thresholds specified in the httpd.conf file by the Mod_Dosevasive directives.
- If the request does not get denied by the preceding check, then just the IP address of the client is hashed into a key. The module will then check the hash table in the same fashion as above. The only difference with this check is that it doesn't factor in what URI the client is checking. It checks to see if the client request number has gone above the threshold set for the entire site per the time interval specified.
you should add the following directives to your httpd.conf file
LoadModule dosevasive20_module modules/mod_dosevasive20.so
-IfModule mod_dosevasive20.c - DOSHashTableSize 3097 - DOSPageCount 2 - DOSSiteCount 50 - DOSPageInterval 1 - DOSSiteInterval 1 - DOSBlockingPeriod 10 -/IfModule
Saturday, December 25, 2010
RHEL 6 is built, and priced, for big shops
Latest iteration of Red Hat's iconic Linux distribution offers some shops a substantial upgrade and, for others, a fork in the road
There's always a sense of finally when a new version of (RHEL) is released. We always know what's coming in the new OS, and generally we know when it'll be available, but we're still working with rapidly aging packages on the previous version and drumming our fingers for the next release.
With RHEL, the longer release cycle is the penalty to be paid for stability. When a new version of RHEL appears, it's been vetted for many moons through the cutting-edge Fedora Linux distribution. Presumably, most of the bugs have been worked out, but that doesn't help when you're busy shoehorning PHP 5.3 and MySQL 5.25 onto an RHEL 5.4 server.
The good news in RHEL 6 is a wealth of new features. These include very significant enhancements, long-awaited updates, and items that have been in place on other nominally less-stable distributions for months, if not years. After all, it's been nearly three years since RHEL 5.0 was released. The net result is that RHEL 6 is easily the best Red Hat Enterprise Linux release yet.
RHEL 6 hardware support
First up are the enhancements to the core system. RHEL 6 defaults to the CFS (Completely Fair Scheduler) process scheduler and the usual CFQ (Completely Fair Queueing) I/O scheduler.
For x86_64 CPUs, RHEL 6 can natively support up to 128 cores and 2TB of RAM. Using other kernel extensions, those limits can be stretched to 4,096 cores and 64TB of RAM, if you're really pushing big iron. Naturally, this is thanks to the Linux 2.6.32 kernel.
Red Hat has also done plenty of work in optimizing memory management with NUMA, which can produce significant performance increases on larger systems.
Virtualization performance is reaching impressive levels. Red Hat says that a virtualized guest environment offers between 85 percent and 95 percent of the performance that you would get by running on native hardware for CPU-intensive operations. It shows that the overhead of virtualization is decreasing and doesn't come with a serious performance penalty. The company also says that its virtualization technology is getting better at handling I/O-heavy workloads too, such as guest environments that run database software.
Saturday, November 20, 2010
Wireless Ethernet PTP Bridge Solution
| ||||||||||||||
| ||||||||||||||
Thursday, November 18, 2010
Wednesday, November 17, 2010
Mobile Broadcast Message Center can text all cell users in a given geo-location
With two thirds of the world population now carrying a mobile phone, we are in the position for the first time to enable a new form of broadcasting. Alcatel-Lucent has announced a new Broadcast Message Center (BMC) which enables targeted government text alerts to be sent to mobile users based on their location – from a small local area to nationwide. The flexibility and scalability of the BMC will save lives in the event of a gas leak, chemical spillage or natural disaster, as it leverages cell broadcast technology to bypass the network congestion that invariably hampers emergencies. The BMC will also be deployed as a commercial broadcast solution, enabling enterprises to communicate with a mobile workforce, or service providers to offer opt-in subscriber services that generate new sources of revenue.
It’s an amazing new world that we are seeing unfold as mobile handsets head towards ubiquity and every person becomes a node on the global wirless network, and one of the biggest immediate opportunities is to be able to notify millions of mobile users within seconds when there is a national, state or local emergency.
Alcatel-Lucent’s BMC extends emergency alerting to mobile users within a geographic area as large as a nation or as small as a few city blocks. Hence, the platform ensures critical warnings and information reach the right people at the right time.
Trials have already been held and the BMC will allow mobile carriers to comply with emergency alerting standards in both the United States and Europe, enabling them to rapidly disseminate warnings and safety information to citizens in an emergency.
Acting as secure interface between an emergency management agency and the service provider’s network, the Broadcast Message Center receives emergency alerts and broadcasts them to cell sites serving mobile customers in a specific geographic area.
For instance, targeted text alerts can be sent to:
The flexibility and scalability of the Broadcast Message Center enables service providers to use it beyond emergency alerting for commercial broadcast services. It provides advertisers and interest groups alternative targeted marketing channels, offers enterprises and municipalities an effective means to communicate with their mobile workforce, while also helping service providers offer opt-in subscriber services that generate new sources of revenue.
It’s an amazing new world that we are seeing unfold as mobile handsets head towards ubiquity and every person becomes a node on the global wirless network, and one of the biggest immediate opportunities is to be able to notify millions of mobile users within seconds when there is a national, state or local emergency.
Alcatel-Lucent’s BMC extends emergency alerting to mobile users within a geographic area as large as a nation or as small as a few city blocks. Hence, the platform ensures critical warnings and information reach the right people at the right time.
Trials have already been held and the BMC will allow mobile carriers to comply with emergency alerting standards in both the United States and Europe, enabling them to rapidly disseminate warnings and safety information to citizens in an emergency.
Acting as secure interface between an emergency management agency and the service provider’s network, the Broadcast Message Center receives emergency alerts and broadcasts them to cell sites serving mobile customers in a specific geographic area.
For instance, targeted text alerts can be sent to:
- Residents threatened by tsunamis, wildfire, tornadoes, floods, etc.
- Students, faculty and parents to inform them of a school or campus emergency
- Consumers and office workers at an airport, shopping mall or business complex to evacuate the location due to a gas leak or suspicious package
- Citizens informing them of an Amber Alert
- Commuters to avoid a chemical spill, highway accident or road closure
The flexibility and scalability of the Broadcast Message Center enables service providers to use it beyond emergency alerting for commercial broadcast services. It provides advertisers and interest groups alternative targeted marketing channels, offers enterprises and municipalities an effective means to communicate with their mobile workforce, while also helping service providers offer opt-in subscriber services that generate new sources of revenue.
Thursday, November 11, 2010
Redhat 6 Released
More reliable. More open. More comprehensive.
With Red Hat Enterprise Linux, you can do more, today.
Red Hat Enterprise Linux is an Enterprise platform well-suited for a broad range of applications across the IT infrastructure. The latest release, Red Hat Enterprise Linux 6, represents a new standard for Red Hat by offering greater flexibility, efficiency, and control. It works across a broad range of hardware architectures, hypervisors, and clouds. Corporations and agencies that standardize on Red Hat Enterprise Linux are free to focus on building their businesses, knowing they have a platform that delivers more of what they need.More reliable. Worry less when you choose Red Hat over Microsoft Windows.
Senior IT managers rank the quality of Red Hat's technology in the top tier of the software vendors list, as the CIO Insight Magazine Vendor Value survey has reported for the past seven years running. Red Hat Enterprise Linux delivers superior uptime to Microsoft, and your ability to install patches faster than for Microsoft Windows Server 2003 or Windows Server 2008 reduces downtime, freeing your time for more strategic IT tasks. Our global team and innovative engineering approach results in a stable operating system platform in which each release is supported for up to 10 years.You can look to Red Hat to offer and track some of the latest innovations in the industry.
In the same vendor value survey, those same senior managers also rate Red Hat as a company that is one of the most reliable software vendors. We deliver high quality products, meet our commitments, and are responsive to our customers' needs. Red Hat consistently delivers a superior experience.
Companies that build their business on technology rely on Red Hat Enterprise Linux. NYSE Euronext, DreamWorks Animation, Salesforce.com, and other diverse companies around the world trust Red Hat Enterprise Linux to minimize downtime, provide sound security, run their largest workloads, and drive their businesses with assurance.
More open. Run the applications your business needs on the platforms you choose.
Today's IT infrastructures are multi-vendor and multi-platform. When you select software for your datacenter, you must consider how well it will operate in that heterogeneous environment. Created with a truly open process, Red Hat Enterprise Linux is an open platform that gives you flexibility, choice, and access to a broad range of innovations to help you control your costs and your future.A subscription to Red Hat Enterprise Linux provides access to any currently-supported version that covers your deployment, whether directly on a server, as a virtualization host, as a guest on the major hypervisors, or in clouds. You can upgrade, migrate, or re-architect without having to renegotiate your agreement.* Moreover, the open source licenses that are delivered through our subscription model give you the right to adapt the system to your needs, on your schedule.
Red Hat collaborates closely with leading independent software vendors (ISVs) and independent hardware vendors (IHVs) to produce an open Enterprise operating system that runs well for all users. Red Hat Enterprise Linux is designed to deliver the latest hardware innovations from many vendors, and is optimized to provide a high-performance and stable platform for a broad portfolio of enterprise and leading-edge applications, including SAP, IBM Lotus Domino, Oracle, SAS, and IBM WebSphere, database, and middleware software.
And all this is supported by Red Hat's global support and engineering teams that work alongside our partners every day.
More comprehensive. Standardize on the platform that covers it all.
Virtualization is a native feature of Red Hat Enterprise Linux 6, allowing your applications to have a consistent environment across physical, virtual, and cloud environments. All the work that you do to set up your applications – configuration, creating security policies, defining policy-driven resource allocation, ensuring regulatory compliance, and optimizing performance through system tuning and application diagnostics – is transportable across all of your deployments. And because Red Hat Enterprise Linux itself is independent of and portable across networks, hardware, and hypervisors – including Hyper-V and VMware – your operations are consistent and efficient wherever you choose to run them.Red Hat Enterprise Linux provides support for your new and existing applications, the latest middleware products, modern cloud software architectures, and new runtime frameworks. But Red Hat provides much more than just a universal interface for applications. Red Hat Enterprise Linux offers a pervasive foundational environment for developing datacenter policies, procedures, and services. From identity management and governance, to a responsive, flexible, and complete Web applications stack, to effective management of scores of servers and massive storage, Red Hat Enterprise Linux should be a critical part of your datacenter infrastructure.
Subscribe to:
Posts (Atom)