Вы находитесь на странице: 1из 7

developerWorks 01.09.

2005

LPI 201:

Linux, c (LPIC-2) 213


cron
cron .
cron .
,
cron. Cron
, - ,
. ( ,
, "cron job.") Cron
syslog.
Cron ,
, , .
-- /etc/crontab, . /etc/cron.d/
, /etc/crontab.
( ,
) /etc/cron.d/,
/etc/crontab.
cron /var/spool/cron/crontabs/$USER.
, crontab.
crontab
.
,
, , - c --
. /etc/cron.daily/, /etc/cron.weekly/ /etc/cron.monthly/
.
--
. , , ,
:
1. ,
$ cat /etc/cron.daily/logrotate
#!/bin/sh

test -x /usr/sbin/logrotate || exit 0


/usr/sbin/logrotate /etc/logrotate.conf

Cron anacron
anacron
. cron, anacron
, n ( n
-- , ,
). , anacron
, delay.
, , ,
, (,
, ).
Anacron /etc/anacrontab.
, ,
. , Linux ,
, anacron ,
, ,
:
2. anacron
$ cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# These replace cron's entries
1
5 cron.daily
nice run-parts --report /etc/cron.daily
7
10 cron.weekly
nice run-parts --report /etc/cron.weekly
@monthly 15 cron.monthly nice run-parts --report
/etc/cron.monthly

crontab
/etc/crontab ( /etc/cron.d/)
crontab. ,
, ,
. crontab ,
(/var/spool/cron/crontabs/$USER).
/etc/crontab ,
. . cron
(
). , , , ,
( ). Asterisk (*)
. ,
, :
# line in /etc/crontab
0 0 * 7-9 2,5 root /usr/local/bin/the-task -opt1 -opt2

scheduling
scheduling pattern' ,
:
@reboot
, .
@yearly
, "0 0 1 1 *".
@annually
, @yearly.
@monthly
, "0 0 1 * *".
@weekly
, "0 0 * * 0".
@daily
, "0 0 * * *".
@midnight
, @daily.
@hourly
, "0 * * * *".
, :
@hourly root /usr/local/bin/hourly-task
0,29 * * * * root /usr/local/bin/twice-hourly-task

crontab
crontab (
/etc/crontab). , crontab -e
.
crontab -l crontab -r.
crontab -u user user,
( ).
/etc/cron.allow,
, .
, /etc/cron.allow ,
/etc/cron.deny, .
, crontab.


at
- ,

at, STDIN
( -f) ,
, .
, at : atq --
; atrm -- ; batch --
at, ,
, .

/etc/cron.allow /etc/cron.deny, at /etc/at.allow


/etc/at.deny . /etc/at.allow, ,
,
. , /etc/at.allow ,
/etc/at.deny, .
, at.

man
at.
HH:MM , , . (
, , ).
12- ,
a.m. p.m. MMDDYY, MM/DD/YY, DD.MM.YY
month-name-day.
: now + N units, N , units minutes, hours, days
weeks. today tomorrow ("" ""),
midnight () noon (), teatime 4 p.m. :
% at -f ./foo.sh 10am Jul 31 % echo 'bar -opt' | at 1:30 tomorrow

. /usr/share/doc/at/timespec.



awk, Perl, bash Python .
() , Text Processing in
Python , Python.
,
, ,

.
.

Linux
bash. bash ,
(
, ls, find, rm cd) ( ,
GNU text utilities).
bash
, bash ,
, set -x,
STDERR.
, , .
-- set -n,
. ,
-n cron
at, .
3. cron, bash
#!/bin/bash
exec 2>/tmp/my_stderr
set -x
# functional commands here

STDERR
STDERR.
.
man bash , .
, set.

, ,
find. ,
. ,
,
. ,
:
% rm foo bar baz bam
% rm 'foo bar' 'baz bam'

( );
,
.
.
, GNU find -print0,
NULL'; xargs -0
, NULL'. ,
, :

4.
#!/bin/bash
# Cleanup some old files
set -x
find /home/dqm \( -name '*.core' -o -name '#*' \) -print0 \
| xargs -0 rm -f

Perl taint mode


Perl -T taint mode. Perl
,
,
, . sudo,
taint mode ,
:
#!/usr/local/bin/perl -T

, ,
, locale (. perllocale),
(readdir(), readlink(), shmread(),
msgrcv(), password, gcos shell,
getpwxxx()) , "tainted".
,
, ,
, , .
taint- (untaint)
:
5. Untainting
if ($data =~ /^([-\@\w.]+)$/) {
$data = $1;
# $data now untainted
} else {
die "Bad data in $data";
# log this somewhere

Perl CPAN
, Perl, --
; Comprehensive
Perl Archive Network (CPAN). RubyGems .
Python, , ,
. ,
bash awk, ,
.
man cpan -- ,

, , ,
. ,
CPAN.
cpan .
(
), cpan
. ,
, YAML
(yaml Ain't Markup Language). YAML , :
% cpan -i YAML # maybe with 'sudo' first

use YAML; .
,
.

Вам также может понравиться