LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02:54 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
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, 03:05 AM   #2
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
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, 07:02 AM   #3
BratPit
Member
 
Registered: Jan 2011
Posts: 250

Rep: Reputation: 100Reputation: 100
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 07:28 AM.
 
2 members found this post helpful.
Old 04-25-2016, 07:43 AM   #4
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
++ What BradPit said.
 
Old 04-25-2016, 08:06 AM   #5
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 928

Rep: Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515Reputation: 515
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, 12:17 PM   #6
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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, 12:09 AM   #7
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
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, 12:22 AM   #8
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
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



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 02:35 PM
How to verify Cronjobs smilemukul Linux - Newbie 1 03-10-2011 02:57 PM
[SOLVED] cronjobs in ubuntu dinakumar12 Linux - Server 7 04-02-2010 05:31 AM
CronJobs error archey Linux - Newbie 4 08-22-2009 05:16 PM
outdated cronjobs bujecas Linux - Software 6 08-04-2005 10:24 AM

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

All times are GMT -5. The time now is 12:36 PM.

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
Open Source Consulting | Domain Registration