When changing Crontab email settings in crontab -e, do I set root as MAILTO=root or MAILTO="root" - cron

I want to change the crontab email address from root to a different address for three particular commands, so that any fails for those commands are sent to the new address, and then back to root for the rest of the cron jobs.
I've opened crontab -e in terminal and set
MAILTO="myaddy#google.com"
followed by the three commands.
Do I then make the next line
MAILTO=root
or
MAILTO="root"
Thank you

Related

Delete/clear active cron job

How can I delete or clear all the cron job that I made previously and just run new cron job that I assigned? I'm using crontab -r but it just clear in the crontab display, but it still runs that cron job and the previous cron job that I have already deleted by using that code.
After I clear cron job using crontab -r, I run crontab -l and it shows this output.
No crontab for trygcp
Use this command,
crontab -e
to access crontab, in there you can deleted specific line or job you created.
About the output you are getting, that only means there is no crontab created under the username trygcp
What you can do is this:
crontab -u [username] -e
Where:
-u define user
-e edit user's crontab
This command will create a crontab under your username, but remember you must have root privilege for you to do this.

Mutt failing as cron job with 'Couldn't lock /sent'

I have a bash script which picks up files from /tmp and emails them to me. I run this script as root and it works perfectly but I am trying to get this automated with crontab.
Added the job to crontab, again running as root, and now I get 'Couldn't lock /sent'.
I managed to confirm it's using the file in /root by changing it's name in Muttrc and tried permission at 600 and 777.
(Also getting an error Segmentation fault, hoping that will go away if I fix the above.)
Anyone any ideas why Mutt is different as a cron job with the same user and the same file.
I simplified the script as follows and is doing exactly the same, works from root shell, but not in crontab.
error:-
Couldn't lock /sent
/data/mediators/email_file: line 5: 1666 Segmentation fault mutt $email -s "test" -i /tmp/test.txt < /dev/null
email_file script:-
#!/bin/bash
email=——#——.com
mutt $email -s "test" -i /tmp/test.txt < /dev/null
crontab:-
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=——#—-.com
HOME=/
54 02 * * * root /data/mediators/email_file
I also added printenv to the job and compared to a server where this runs OK. The difference is that the working system has USER=root, whereas the non-working one does not show this variable as being set.
The issue is combination of HOME=/ env variable in crontab and default mutt record configuration which defaults to ~/sent.
mutt stores sent emails in the record file. So choose whether you want to keep them (fix crontab's env var HOME or set mutt's record to meaningful value.
Add this option to mutt command in email_file If you want to set it:
-e 'set record=/root/sent'
or unset it with:
-e 'unset record'
You can find more in man pages muttrc(5)
record
Type: path
Default: “~/sent”
This specifies the file into which your outgoing messages should be appended. (This is meant as the primary method for saving a copy of your messages, but another way to do this is using the “my_hdr” command to create a “Bcc:” field with your email address in it.)
The value of $record is overridden by the $force_name and $save_name variables, and the “fcc-hook” command. Also see $copy and $

UNIX : Editing system crontab (/etc/crontab) and restarting cron services after edit

I want to edit system cron tab (/etc/crontab). I read that crontab -e is the best way to edit crontab and you need not restart cron services if you edit this way. However I am not able to edit /etc/crontab using crontab -e (this command edits the crontab associated with the user, not system crontab). So is there any better way of editing /etc/crontab (other than using VI editor- which I am doing now). Do I need to restart cron services if I edit /etc/crontab using VI edior?
There are two ways of cronjobs, one is by editing /etc/crontab and sending a SIGHUP the cron daemon. The other way is to use crontab -e to edit
a crontab entry, which is done for the current user or the one mentioned with -u. The -u option can only be used by root. The crontabs
created this way can be found in the directory
/var/spool/cron/crontabs/
and are named after the user with which uid the jobs will be started. In this case you don't need to SIGHUP cron, a normal user can't do this anyway.
Note: The syntax is slightly different to /etc/crontab: You can't enter an other user name to execute the cronjob.
You could do something like this
echo "0 23 * * * yum -y update > /dev/null 2>&1" >> /var/spool/cron/root
Then verify with
crontab -l

questions on crontab

I have following questions on cron.
What is the preferred way for automating cron jobs? Using a) crontab command-line options (eg. crontab -e) or b) editing /etc/crontab. What is the difference between the two? It's not exactly clear to me.
Is crontab user specific? If I am logged in as a a user say "anup", and add jobs using crontab -e, will the job be user-specific? However, in some of the cron examples I checked online, username is provided as a field between the time string and the command to be executed.
Can the 'Mail to user" option be controlled for each job? As in, for job 1: MailTO: root for job 2: MailTO: anup.
The crontab utility is a commandline tool that maintains the crontab files for individual users.
crontab -l lists/views the crontab for the current user
crontab -e edits the crontab
You can type man crontab for full documentation on most linux/mac systems.
The crontab is specific to the user. If you're logged in as anup, then crontab -e will edit anup's crontab file. You can specify the user with the -u flag (crontab -u)
I'm not 100% sure, but I believe that you can specify a new MAILTO= setting and it will take effect for all processes executed afterwards.

crontab entry for individual user

On my RHEL5 box, I have so far set up cron jobs by placing entries in the /etc/crontab file which is for safely reasons, only editable by root.
Are there other ways to set up cron jobs for individual users? Preferably, I would like each user to have their own cron file that they can edit at will without requiring root privileges.
Can this be done?
Users can create and edit their own crontabs with crontab -e. They can view their crontab with crontab -l. They can remove their crontab with crontab -r.
man -s1 crontab for more information.
crontab entry is user specific only. a user can make/schedule its own jobs in crontab or you can say that all files on which user is having access
http://www.weblogitech.com/2015/12/what-is-cron-tab-in-linux-and-unix.html

Resources