Pages

Tuesday, January 29, 2008

run-parts : run scripts or programs in a directory

I kept updating my cron to automate some routine tasks. however noticed many a things in cron are not giving results to my expectation. Was kept suspecting cron is not working or got corrupted.But found errors in crontab entries using run-parts .

here we see how cron and run-scripts works


cron
----
Cron daemon to execute and scheduled commands.
At start it search in cron spool area: /var/spool/cron/ and After that cron.{d,hourly,daily,monthly} and log in /var/log/cron.


Cron Related commands
---------------------

Usage: /etc/init.d/cron {start|stop|restart|reload|force-reload}

usage: crontab [-u user] file
crontab [-u user] { -e | -l | -r }
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)


run-parts
---------
run-parts runs all the executable files named within constraints described below, found in directory directory.Other files and directories are silently ignored.


Usage: run-parts [OPTION]... DIRECTORY
--test print script names which would run, but don't run them.
--list print names of all valid files (can not be used with
--test)
-v, --verbose print script names before running them.
--report print script names if they produce output.
--reverse reverse execution order of scripts.
--exit-on-error exit as soon as a script returns with a non-zero exit
code.
--lsbsysinit validate filenames based on LSB sysinit specs.
-u, --umask=UMASK sets umask to UMASK (octal), default is 022.
-a, --arg=ARGUMENT pass ARGUMENT to scripts, use once for each argument.
-V, --version output version information and exit.
-h, --help display this help and exit.


example :

#run-parts --list /etc/cron.hourly ( list files to executed by run-parts )
#run-parts --test /etc/cron.hourly ( list and test files inside directory )
#run-parts /etc/cron.hourly ( executes files and there output to stdout )

1 comment:

Ravikumar Naik said...

Hi,

Can u please go step further by explaining with example.