I have set a cronjob for every 15 mins and have also set my SMTP email, but this cron job is sending me an email every 15 min with subject as my cron command and user as "root" . so i want to stop receiving this email without disturbing my SMTP config
i just append this to my cron command
/dev/null 2>&1
sources:
http://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/
Related
I'm trying to get the cron job to send me an email directly after the script execution and get the last logs into the body of the email
21 14 * * * /opt/anaconda/bin/python /Path/to/Script/script.py >> /Path/to/logfile/log.txt 2>&1 | mail -s "cronjob OK" "first#mail.x,second#mail.x"
How could I do that? what should I add?
Thanks in advance.
Your script is not producing any output because you just redirected it to a file.
cron will send any output by email to the owner of the cron job anyway. You can specify a different address with MAILTO in some cron implementations.
MAILTO=first#mail.x,second#mail.x
21 14 * * * /opt/anaconda/bin/python /Path/to/Script/script.py 2>&1 | tee -a /Path/to/logfile/log.txt
The tee command saves a copy of standard input to the file (-a says to append instead of overwrite) and to standard output.
If you need more control over the generated message (e.g. to use a different Subject: header if Cron's is not acceptable) maybe keep the tee but put back the pipe to mail.
I am trying crontab but crontab for email is not working.However, I want that crontab runs a shell script and that shell script runs a python script.
One crontab I tried is
* * * * * echo " This is current date and time $(date)"
but this is not getting printed on screen. I don't understand what is wrong I am doing.
for sending the email form this command.
echo " This is a message " | mailx -s "Subject" mymail#email.com
you need to make sure port 25 is open on your system.
you can use the mailq command for check email in the queue on your system.
you can check local port is open or not from
telnet localhost 25
nc localhost 25
Since couple of days i'm getting unwanted cron status emails from my server.
Tried MAILTO="" but still receiving mails.
Please help me to get rid of this emails.
Thanks in advance.
cron will email you anything that appears on stdout, so redirect stdout to /dev/null in your crontab entries. eg:
5 21 * * 1-5 { echo stuff to do; } >&/dev/null
I have a GMail account that is set to only receive an email with a certain subject.
I need some linux commands to trigger when it finds unread versions of this email.
The commands are just application calls so I could record my desktop while it runs.
xrandr --size 1360x768
timeout 2h recordmydesktop
xrandr --size 1366x768
I already created a filter on gmail for the email itself, but now I have no idea what to do next. I was told to set up fetchmail that would fetch unread emails in the folder I set-up.(and mark the newly fetched email as read on gmail so it wouldn't read the same mail over and over). This is the script I got, but i'm not sure if ths script does what I need it to.
poll imap.gmail.com protocol IMAP
user "l**********#gmail.com"
password '*****'
folder 'Pic*******'
fetchmail -c
keep
ssl
Next is that I was told to set up a procmail script to trigger my linux commands whenever fetchmail says that it found an unread version of the email. but I'm not exactly sure how to do it. I also need to set up cronjob to have this script trigger every few minutes.
fetchmail is good at downloading messages. procmail is good at filtering messages and executing arbitrary linux commands based on the mail received.
To set up fetchmail to run every 10 minutes as a cronjob and pass the mail it receives to procmail, run crontab -e and add the following line:
*/10 * * * * /usr/bin/fetchmail -N -d0 -f $HOME/.fetchmailrc -m "/usr/bin/procmail $HOME/.procmailrc"
You will need to create a ~/.procmailrc file to do the filtering and executing.
You have not said what commands you want to run. As an example, just for the purpose of giving you ideas, the following stanza from a ~/.procmailrc file selects messages from somebody#example.com with the subject heading New File. The body of the message is then uudecoded and the output from the uudecoder is then untarred:
:0 w
* ^From:.*somebody#example.com
* ^Subject: New File
| uudecode -o /dev/stdout | tar -xzC /var/tmp/
The requirement to run X commands somewhat complicates matters. Cron is not really suitable -- even if your computer is only turned on when you are logged in, the general X architecture is based on privilege separation -- commands running in your current X session have access to the GUI, others do not.
Running Fetchmail and Procmail from within your X session is kind of awkward as well, but if you have a dedicated email account for this task, I don't suppose you mind accidentally losing an email message occasionally.
Thus, instead of a Cron job, I would suggest a simple background script running from your .xsession or similar.
#!/bin/sh
while true; do
fetchmail -N -d0 -f $HOME/.fetchmailrc -m "/usr/bin/procmail $HOME/.procmailrc"
sleep 600
done
The Procmail recipe could look something like
:0
* ^Subject: whatever
| xrandr --size 1360x768 ;\
timeout 2h recordmydesktop; \
xrandr --size 1366x768
My date command -
May 19 20:28:00
Crontab file -
ubuntu#ip:/etc/cron.daily$ crontab -l
24 20 19 5 1 /opt/sw/p3/scratch/test.py > /opt/sw/p3/scratch/test1.txt
Based on the above command and date, My job should have run at 20:24 on May 19 but I dont see any output in my test1.txt
test.py just prints a statement -
print "I will be run soon"
Why my crontab job did not run at that time?
If you are running this cron job on a remote server, please verify whether the server's timezone is same as your's. If not you can change the server default timezone and try setting the cron job again to a different date/time.