LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-27-2020, 06:09 PM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,374

Rep: Reputation: Disabled
can I see a log of what the crontab actually did?


I put some backup procedures in the crontab. Is there a log somewhere of whether the crontab actually executed them? It would make me feel better if I could see proof at least once and know it didn't go wrong.
 
Old 06-27-2020, 07:53 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,321
Blog Entries: 28

Rep: Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141
A web search turned up lots of confusing stuff about cron logs, but, if MX does not have a /var/log/cron file, my best guess is to check /var/log/syslog. (I have a VM of MX, but I'm not running any cron jobs on it.)

This might help: https://www.cyberciti.biz/faq/how-to...-ubuntu-linux/
 
1 members found this post helpful.
Old 06-28-2020, 09:15 AM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
By default, crontab will send email to the user's account(user@localhost) every time a cron job runs. For this to properly occur, you need to have some MTA(message or mail transfer agent) installed to send the email. The two most common are Postfix and Sendmail. If you install Postfix just go with the defaults and crontab should be able to send email. To read crontab's email messages, install mutt, a command line email reader. Note, neither mutt nor Postfix are usually installed by default.
Now for reading your crontab messages, just open a terminal and run:
Code:
$ mutt
if you are running crontab from your user account or
Code:
$ sudo mutt
if you are running crontab from the admin account. Here's what it looks like on my box:
Code:
q:Quit  d:Del  u:Undel  s:Save  m:Mail  r:Reply  g:Group  ?:Help
   1     Jun 28 Cron Daemon     (  88) Cron <patrick@Fortress> /home/patrick/bin/desk_cron




---Mutt: /var/mail/patrick [Msgs:1 Post:1 3.6K]---(threads/date)---------------------------------------------------------------------------------------------------------------------(all)---
Selecting the email message you're interested in will give the complete output that the cron job generated when it was run like so
Code:
i:Exit  -:PrevPg  <Space>:NextPg v:View Attachm.  d:Del  r:Reply  j:Next ?:Help
Date: Sun, 28 Jun 2020 08:35:35 -0500 (CDT)
From: Cron Daemon <root@Fortress.attlocal.net>
To: patrick@Fortress.attlocal.net
Subject: Cron <patrick@Fortress> /home/patrick/bin/desk_cron

receiving incremental file list

sent 132 bytes  received 118.62K bytes  237.50K bytes/sec
total size is 65.46G  speedup is 551,279.97
receiving incremental file list

sent 26 bytes  received 2.20K bytes  4.46K bytes/sec
total size is 14.44G  speedup is 6,478,651.74
receiving incremental file list

sent 81 bytes  received 16.22K bytes  10.86K bytes/sec
total size is 29.66G  speedup is 1,820,045.18
receiving incremental file list

sent 26 bytes  received 1.30K bytes  884.67 bytes/sec
total size is 17.32G  speedup is 13,051,676.07
receiving incremental file list

-   - 1/1: Cron Daemon            Cron <patrick@Fortress> /home/patrick/bin/de -- (24%)
You use the space bar to scroll through the message. Crontab will send out a separate email every time a cron job runs and you can easily see if something is amiss with your backup cron job.

Last edited by kilgoretrout; 06-28-2020 at 11:38 AM.
 
1 members found this post helpful.
Old 06-28-2020, 11:00 AM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by newbiesforever View Post
I put some backup procedures in the crontab. Is there a log somewhere of whether the crontab actually executed them? It would make me feel better if I could see proof at least once and know it didn't go wrong.
There's always email. Add the line:
Code:
MAILTO=your-email-addr@your-hostname
to your crontab (I place it near the top) and you'll receive an email after the cron job completes that contains the output from your backup script. It's helpful to add "2>&1" to the end of the command you are using for the backups. The downside to this method for root's cron jobs is that "your-email-addr@your-hostname" will receive all of root's cron job emails. Probably not desirable (though someone ought to be reading those).

An alternate method of receiving that email notification (and I lean toward this one) is to pipe the output of the backup script into mailx (or similar)
Code:
00 02 * * * run_backups 2>&1 | mailx -s "BACKUP Results" user-who-monitors-backups@your-hostname
If you have different users who are in charge of different aspects of the system, this allows you to have messages going to specific people (rather than subjecting an individual (or group) to the potential firehose created by the MAILTO variable). If you have a backup team, you can define an email alias (example: "backup_admins") in "/etc/aliases" containing the list of backup admins' email addresses and specify that alias in the email command.
Code:
00 02 * * * run_backups 2>&1 | mailx -s "BACKUP Results" backup_admins@your-hostname
Dedicated storage team? Same thing can be done for those folks.

HTH...
 
2 members found this post helpful.
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
"But did they actually MAKE those (non-descript) ice-cream bars?" sundialsvcs General 19 04-30-2018 03:27 PM
Sendmail log: did it actually accepted the message? cheerful Linux - Software 10 02-21-2017 05:12 AM
LXer: Appeals court: Actually, Newegg did win that case LXer Syndicated Linux News 0 07-31-2015 08:10 PM
crontab -e what does it actually edit? wimnat Linux - General 5 05-26-2009 10:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:22 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
Open Source Consulting | Domain Registration