December 13th, 2001, 08:26 PM
Help required with Crontab
Hi there I am trying to create a crontab as root to run a nightly job to rotate our webserver logs, however I am unable to get it to work correctly.
The crontab file is as follows:-
The rotateLogs.sh file contains:
# This is a comment.
0 0 * * * /web/clients/know_less/rotateLogs.sh
But when it tries to run it does not work at all. can someone offer me some advise in what I may be doing incorrectly and how I woul dbest set this up.
The rotateLogs.pl file is the perl script that does all the work, and that works fine. The cron must be run as root as I need to restart apache.
December 13th, 2001, 10:14 PM
>> The rotateLogs.sh file contains
You can set your cron entry to be the exact Perl script, you don't need to call your shell script first.
>> I am unable to get it to work correctly
Such answer is extremely unhelpful. You should start here -> [NEW USERS] - How to post a question.
1) What did you do?
2) What happened?
3) What you expected it to do?
If you have a Perl question, post to Perl forum, not here.
>> The cron must be run as root as I need to restart apache
*BSDs have newsyslog(8) to do this kind of stuffs and it will HUP Apache automatically.
Here is an example of /etc/newsyslog.conf:
/var/log/apache/access_log 600 7 300 * Z /var/run/httpd.pid
This will rotate access_log when it reaches 300kb.
December 14th, 2001, 12:05 AM
Hey there thanks for those comments, but I actually worked it out and it appears to be working after some mods to the perl script and everything else.
I had to rename it from .pl to .cgi for some reason as it would always come back with filenot found for the .pl extension.
as far as what I am doing this for is, not so much based on file size but for ease of use....
But thanks for the comments and suggestions anyway
December 14th, 2001, 01:17 AM
>> it would always come back with filenot found for the .pl extension
1) Make sure you specify a PATH env in your cron like so:
2) trim all ^M (\r\n) by running perl -i -pne 's/\r\n/\n/g' *.pl. Check here -> Basic Perl Question
Having a .pl in your cron is absolutely fine and dozen of my scripts in crontab are with a .pl extension like so:
*/30 * * * * /usr/local/sbin/relay-ctrl-age
0 */12 * * * cvsup /usr/local/etc/cvsup/ports-supfile -g 2>&1 | mail -s "`hostname -s` - CVSup ports at `date`" cron
30 8 * * * /var/qmail/bin/qmail-scanner-queue.pl -z 2>&1 > /dev/null
0 */4 * * * /var/private/rotate.pl 2>&1 > /dev/null
What my rotate.pl really do is to rotate all .gz files (rotated by newsyslog) back to human-readable normal file and move them away from /var/log/ to another location with proper /date/month/day format for ease of reading.
Last edited by freebsd; December 14th, 2001 at 01:20 AM.
December 16th, 2001, 12:44 AM
Delaying initialization of a daemon on startup
I am using Samba to allow easier access to my freeBSD box from my windows box and all is fine when I start the samba daemons smbd and nmbd manually. However when I place the init script in /usr/local/etc/rc.d there appears to be a conflict with one of the other init scripts in that directory (I know this because when I disable/chmod-x all other scripts in /usr/local/etc/rc.d, the samba daemons runs fine). The other init scripts are for apache and mysql, my money would be on it being apache causing the problems... but this is aside...
I'm now after a method of delaying the execution/initilization of httpd/mysqld when I boot up (or alternatively delaying init of smb).
What software would I use to achieve this aim?
I read through the info on cron (I'm not overly familiar with cron) and can't see how it could be used to run a process 'x' amount of time after boot up .
Many thanks in advance,
PS - what does 'rc.d' stand for??? And why is the etc directory called 'etc'???
December 16th, 2001, 04:00 AM
>> What software would I use to achieve this aim?
You can implement some sort of System V style by renaming your smbfs.sh to ysmbfs.sh and nmbd.sh to znmbd.sh so they have lower priority. Keep in mind, the order is: 0-9 -> A-Z -> a-z. You also can rename whatever script that should have the highest priority by putting a 0 as the 1st character of the startup script.
Really, FreeBSD supposed to be the big brother among the 3 (Net, Open and Free), but some of the implementation they are using is really outdated and inefficient. Just to name a few: Old version of Perl, old version of X and poor rc (init mechanism). NetBSD beats FreeBSD in all 3 of these categories.
December 16th, 2001, 10:42 AM
Ah yes, this makes sense - I remember reading something about this method for ordering init script execution somewhere (perhaps periodic man?). Thanks I will try this and see how it goes. This in fact makes good sense, taking the following into account...
I narrowed the problem down to the apache rc script as the cause of the nmbd rc init coredump, so it appears the problem was that the httpd init script was still running when the smbd init script was called and there was a clash of some kind.
Another quick question - I notice that the periodic scripts have a similar 'alphachronological' init sequence:
Would it be in keeping with the FreeBSD 'schema' to use this style for rc scripts?
-rwxr-xr-x 1 root wheel 1273 Sep 18 18:30 100.clean-disks
-rwxr-xr-x 1 root wheel 1401 Sep 18 18:30 110.clean-tmps
-rwxr-xr-x 1 root wheel 1094 Sep 18 18:30 120.clean-preserve
-rwxr-xr-x 1 root wheel 697 Sep 18 18:30 130.clean-msgs
-rwxr-xr-x 1 root wheel 1058 Sep 18 18:30 140.clean-rwho
-rwxr-xr-x 1 root wheel 1138 Sep 18 18:30 150.clean-hoststat
-rwxr-xr-x 1 root wheel 1737 Sep 18 18:30 200.backup-passwd
-rwxr-xr-x 1 root wheel 998 Sep 18 18:30 210.backup-aliases
Thanks in advance,
>>PS - just made the following modification to /usr/local/etc/rc.d:
which works like a dream.
[munk /home/munk] # ls -al /usr/local/etc/rc.d/
drwxr-xr-x 2 root wheel 512 Dec 16 16:49 .
drwxr-xr-x 6 root wheel 512 Dec 15 15:24 ..
-r-xr-xr-x 1 root wheel 392 Dec 4 02:02 100.samba.sh
-rwxr-x--x 1 root wheel 181 Sep 13 20:29 200.mysql-client.sh
-rwxr-x--x 1 root wheel 332 Sep 14 04:00 210.mysql-server.sh
-rwxr-x--x 1 root wheel 434 Sep 13 19:58 300.apache.sh
I must admit I do like FreeBSD in its 'logically correct' simplicity compared against linux which seems to throw files all over the place (as you've remarked on regarding hier(7) in various posts vis-a-vis linux inconsistent hierarchy/directory structuring).
Last edited by munkfish; December 16th, 2001 at 10:57 AM.
December 16th, 2001, 08:11 PM
>> Would it be in keeping with the FreeBSD 'schema' to use this style for rc scripts?
Yes, just to compensate FreeBSD's poor/outdated rc mechanism for local scripts at /usr/local/etc/rc.d/ but not with /etc/rc*.
I bet FreeBSD will steal/implement NetBSD way of doing all this rc stuffs approach sooner or later.
So what the hell is all about NetBSD in this category?
NetBSD doesn't use /usr/local/etc/rc.d. /etc/rc.local also is not recommended (that is for OpenBSD). NetBSD implement a kickass way of start/stop boot scripts all in one centralize place -> /etc/rc.d/scriptname_here. Like ports system, in /etc/rc.d/*, all the script dependencies are checked and all scripts are highly linked together. All these are controlled by a script at /etc/rc.subr. Say you start a script by running "/etc/rc.d/script_name start", all the require scripts will first be started/checked. If they haven't started, you will be asked to start those scripts prior to starting your script_name start.
So as you can see, in FreeBSD, renaming sciptname to 010.scriptname.sh helps controlling the startup order but it doesn't check for dependencies.
Last edited by freebsd; December 16th, 2001 at 08:14 PM.
December 17th, 2001, 04:40 PM