BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old December 13th, 2001, 08:26 PM
mystik_web's Avatar
mystik_web mystik_web is offline
No one Important
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Australia
Posts: 524 mystik_web User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 8
Send a message via ICQ to mystik_web
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:-

Code:

# This is a comment.

SHELL=/bin/sh

MAILTO=me@whoever.com

0 0 * * * /web/clients/know_less/rotateLogs.sh


The rotateLogs.sh file contains:

Code:
#!/bin/sh
cd /path/to/script/

./rotateLogs.pl


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.

Cheers

Reply With Quote
  #2  
Old December 13th, 2001, 10:14 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> 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 -> http://forums.devshed.com/showthrea...24097&forumid=5

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.

Reply With Quote
  #3  
Old December 14th, 2001, 12:05 AM
mystik_web's Avatar
mystik_web mystik_web is offline
No one Important
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Australia
Posts: 524 mystik_web User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 8
Send a message via ICQ to mystik_web
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

Reply With Quote
  #4  
Old December 14th, 2001, 01:17 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> 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:

PATH=/usr/local/bin:/usr/bin:/bin

2) trim all ^M (\r\n) by running perl -i -pne 's/\r\n/\n/g' *.pl. Check here -> http://forums.devshed.com/showthrea...23490&forumid=6

Having a .pl in your cron is absolutely fine and dozen of my scripts in crontab are with a .pl extension like so:

SHELL=/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
*/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.

Reply With Quote
  #5  
Old December 16th, 2001, 12:44 AM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 9
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,
Jez

PS - what does 'rc.d' stand for??? And why is the etc directory called 'etc'???

Reply With Quote
  #6  
Old December 16th, 2001, 04:00 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> 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.

Reply With Quote
  #7  
Old December 16th, 2001, 10:42 AM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 9
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:
Code:
-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
etc...


Would it be in keeping with the FreeBSD 'schema' to use this style for rc scripts?
Thanks in advance,
Jez

>>PS - just made the following modification to /usr/local/etc/rc.d:
Code:
[munk /home/munk] # ls -al /usr/local/etc/rc.d/
total 6
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

which works like a dream.

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.

Reply With Quote
  #8  
Old December 16th, 2001, 08:11 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> 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.

Reply With Quote
  #9  
Old December 17th, 2001, 04:40 PM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 9
Ok... thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Help required with Crontab


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway