LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-25-2016, 03:54 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,408

Rep: Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019
Combining cronjobs?


Hi,

I have two daily cronjobs for SquidAnalyzer and Squid log rotation. I'd like to combine them, and I wonder what's the best solution for this.

Every day at 13:00 I'm running /usr/bin/squid-analyzer. This command parses /var/log/squid/access.log and generates a detailed report about web usage. On some machines with many clients, this command can run for several minutes.

Next thing I have to do is run another cronjob for /usr/sbin/squid -k rotate, to rotate Squid's log files. Again, on networks with many clients, /var/log/squid/access.log* can get quite huge, so rotating the logs is vital to keep things manageable.

What would be the syntax to execute one cronjob after another? Can I simply put the following in a cronjob?

Code:
/usr/bin/squid-analyzer && /usr/sbin/squid -k rotate
Cheers,

Niki
 
Old 04-25-2016, 04:05 AM   #2
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 7,740

Rep: Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304Reputation: 6304
Why not write a script that calls the two commands, one after the other, and then you schedule the script as a cron job?
 
1 members found this post helpful.
Old 04-25-2016, 08:02 AM   #3
BratPit
Member
 
Registered: Jan 2011
Posts: 237

Rep: Reputation: 85
Why not logrotate . It's just for logs.

Sample:

Quote:
/etc/logrotate.d/squid
Quote:
/var/log/squid/access.log* {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
prerotate
/usr/bin/squid-analyzer
endscript
}

or if it,s important at specific time of the day different from cron.daily do this by cron job:

Quote:
logrotate -f /etc/logrotate.d/squid
it's only for squid log not affects regular logrogate job.

Last edited by BratPit; 04-25-2016 at 08:28 AM.
 
2 members found this post helpful.
Old 04-25-2016, 08:43 AM   #4
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,316

Rep: Reputation: Disabled
++ What BradPit said.
 
Old 04-25-2016, 09:06 AM   #5
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 -current (started with 13.37(32))
Posts: 504

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by kikinovak View Post
Can I simply put the following in a cronjob?

Code:
/usr/bin/squid-analyzer && /usr/sbin/squid -k rotate
Cheers,

Niki
It will work, or if you want run squid -k rotate anyway after, could be '/usr/bin/squid-analyzer;/usr/sbin/squid -k rotate'
 
Old 04-25-2016, 01:17 PM   #6
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 6,248

Rep: Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003Reputation: 4003
Quote:
Originally Posted by kikinovak View Post
Code:
/usr/bin/squid-analyzer && /usr/sbin/squid -k rotate
That command will run the second half only if the first command succeeds. If, for some reason, squid-analyzer bombs out and throws an exit code other than 0 (0 means a successful exit without errors), your logs won't rotate. If you want both commands to run no matter what, you'd want to do one of the following: replace the && with a ; (semicolon), create a shell script with them either on separate lines (as Eric mentioned), or separate them into separate cron jobs (which could entail using logrotate as BratPit mentioned).

See this stackexchange answer to see the differences between && || and ;
 
1 members found this post helpful.
Old 04-28-2016, 01:09 AM   #7
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,402

Rep: Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976
See crontab(1) - jobs can be made to depend on other jobs. I've never used this functionality, but I've run across it several times in the manual page and filed it away as something that could be useful at some point. Here we are. :-)
 
2 members found this post helpful.
Old 04-28-2016, 01:22 AM   #8
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,408

Original Poster
Rep: Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019Reputation: 2019
Thanks for your numerous answers, guys. For some reason, I've found out that SquidAnalyzer simply stopped working, and I have this problem to tackle first before giving the above suggestions a try.

Cheers,

Niki
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Slackware and cronjobs kikinovak Slackware 5 07-08-2013 03:35 PM
How to verify Cronjobs smilemukul Linux - Newbie 1 03-10-2011 03:57 PM
[SOLVED] cronjobs in ubuntu dinakumar12 Linux - Server 7 04-02-2010 06:31 AM
CronJobs error archey Linux - Newbie 4 08-22-2009 06:16 PM
outdated cronjobs bujecas Linux - Software 6 08-04-2005 11:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration