Crontab [SOLVED]

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
User avatar
~FLOW~
Level 3
Level 3
Posts: 108
Joined: Tue Mar 12, 2013 3:23 am

Crontab [SOLVED]

Post by ~FLOW~ »

Hello all !!
I'm trying to use crontab but it doesn't do anything
This is what I've tried on a fresh virtual machine :

Code: Select all

test@test-VirtualBox:~$ crontab -e
inside the config file, at the end -> /tmp/crontab.gVyWNL/crontab :

Code: Select all

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
* * * * * /usr/bin/firefox
Save & Restart.
Nothing happens

OBS.
I don't understand what to make of this lines
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
and

Code: Select all

test@test-VirtualBox:~$ grep CRON /var/log/syslog 
May  8 09:14:02 test-VirtualBox CRON[2466]: (test) CMD (/usr/bin/firefox)
May  8 09:14:02 test-VirtualBox CRON[2465]: (CRON) info (No MTA installed, discarding output)
May  8 09:15:01 test-VirtualBox CRON[2473]: (test) CMD (/usr/bin/firefox)
May  8 09:15:01 test-VirtualBox CRON[2472]: (CRON) info (No MTA installed, discarding output)
May  8 09:16:01 test-VirtualBox CRON[2491]: (test) CMD (/usr/bin/firefox)
May  8 09:16:01 test-VirtualBox CRON[2490]: (CRON) info (No MTA installed, discarding output)
May  8 09:17:01 test-VirtualBox CRON[2502]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  8 09:17:01 test-VirtualBox CRON[2503]: (test) CMD (/usr/bin/firefox)
May  8 09:17:01 test-VirtualBox CRON[2501]: (CRON) info (No MTA installed, discarding output)
May  8 09:18:01 test-VirtualBox CRON[2514]: (test) CMD (/usr/bin/firefox)
May  8 09:18:01 test-VirtualBox CRON[2513]: (CRON) info (No MTA installed, discarding output)
May  8 09:19:01 test-VirtualBox CRON[2521]: (test) CMD (/usr/bin/firefox)
May  8 09:19:01 test-VirtualBox CRON[2520]: (CRON) info (No MTA installed, discarding output)
May  8 09:20:01 test-VirtualBox CRON[2528]: (test) CMD (/usr/bin/firefox)
May  8 09:20:01 test-VirtualBox CRON[2527]: (CRON) info (No MTA installed, discarding output)
May  8 09:21:01 test-VirtualBox CRON[2546]: (test) CMD (/usr/bin/firefox)
May  8 09:21:01 test-VirtualBox CRON[2545]: (CRON) info (No MTA installed, discarding output)
May  8 09:22:01 test-VirtualBox CRON[2555]: (test) CMD (/usr/bin/firefox)
May  8 09:22:01 test-VirtualBox CRON[2554]: (CRON) info (No MTA installed, discarding output)
May  8 09:23:01 test-VirtualBox CRON[2564]: (test) CMD (/usr/bin/firefox)
May  8 09:23:01 test-VirtualBox CRON[2563]: (CRON) info (No MTA installed, discarding output)
I have also tried with MAILTO="" at the begining of the file, but still no result.

Code: Select all

MAILTO=""
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
* * * * * /usr/bin/firefox
Last edited by ~FLOW~ on Fri May 08, 2020 6:51 am, edited 1 time in total.
Linux Mint 20
Cinnamon 4.6
Kernel 5

Be patient !!
What seams easy for you now, for a newbie might be a monumental helping hand.
An efficient pack will move as fast as the slowest member.

User avatar
deck_luck
Level 5
Level 5
Posts: 835
Joined: Mon May 27, 2019 6:57 pm
Location: R-4808 North

Re: Crontab

Post by deck_luck »

~FLOW~ wrote:
Fri May 08, 2020 2:52 am
Hello all !!
I'm trying to use crontab but it doesn't do anything
This is what I've tried on a fresh virtual machine :

Code: Select all

test@test-VirtualBox:~$ crontab -e
inside the config file, at the end -> /tmp/crontab.gVyWNL/crontab :

Code: Select all

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
* * * * * /usr/bin/firefox
A cronjob must be a NON-interactive program. You are attempting to use an interactive program (firefox). If you need a simple cronjob for testing using the following

Code: Select all

* * * * * /bin/date >> crontest.out
The cronjob test will update the crontest.out file in your home directory every minute with the current date and time.
🐧Linux Mint 19 XFCE 💡Give a friend a fish, and you feed them for a day. Teach a friend how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.

User avatar
~FLOW~
Level 3
Level 3
Posts: 108
Joined: Tue Mar 12, 2013 3:23 am

Re: Crontab

Post by ~FLOW~ »

well...that was good to know :))
So if I want to start FF for example, I shoud use a StartTB.sh ?
Linux Mint 20
Cinnamon 4.6
Kernel 5

Be patient !!
What seams easy for you now, for a newbie might be a monumental helping hand.
An efficient pack will move as fast as the slowest member.

User avatar
~FLOW~
Level 3
Level 3
Posts: 108
Joined: Tue Mar 12, 2013 3:23 am

Re: Crontab

Post by ~FLOW~ »

or maybe I started with the wrong question, what should I do if I want to start 2 times per day Thunderbird. Or another command at a particular time in a day.
Linux Mint 20
Cinnamon 4.6
Kernel 5

Be patient !!
What seams easy for you now, for a newbie might be a monumental helping hand.
An efficient pack will move as fast as the slowest member.

rene
Level 16
Level 16
Posts: 6573
Joined: Sun Mar 27, 2016 6:58 pm

Re: Crontab

Post by rene »

The thing with cronjobs is that they run in/with a by default "non-graphical environment" which is to say that for example Firefox misses the DISPLAY environment variable. It works if you say e.g.

Code: Select all

* * * * * env DISPLAY=":0" firefox
Another usual missee is DBUS_SESSION_BUS_ADDRESS but in the case of Firefox you don't need it. For situations in which you do, on Mint 19+,

Code: Select all

* * * * * env DISPLAY=":0" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus" theprogram
The bit of log you quoted stating "(CRON) info (No MTA installed, discarding output)" says that, well, no MTA is installed and could be taken as stimulus to install an MTA. No real need in this case, i.e., in the Firefox case you'd just be emailed Firefox stating it needs the DISPLAY environment variable, but if interested see e.g. viewtopic.php?p=1537513#p1537513

None of which would by the way be to say that cron is not not intended for launching graphical/interactive programs at the very least. But, sure, ...

User avatar
~FLOW~
Level 3
Level 3
Posts: 108
Joined: Tue Mar 12, 2013 3:23 am

Re: Crontab

Post by ~FLOW~ »

Thank you so much !!!
:D
Linux Mint 20
Cinnamon 4.6
Kernel 5

Be patient !!
What seams easy for you now, for a newbie might be a monumental helping hand.
An efficient pack will move as fast as the slowest member.

Post Reply

Return to “Newbie Questions”