Page 1 of 1

Crontab [SOLVED]

Posted: Fri May 08, 2020 2:52 am
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

Re: Crontab

Posted: Fri May 08, 2020 4:44 am
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.

Re: Crontab

Posted: Fri May 08, 2020 5:12 am
by ~FLOW~
well...that was good to know :))
So if I want to start FF for example, I shoud use a StartTB.sh ?

Re: Crontab

Posted: Fri May 08, 2020 5:31 am
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.

Re: Crontab

Posted: Fri May 08, 2020 5:59 am
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, ...

Re: Crontab

Posted: Fri May 08, 2020 6:50 am
by ~FLOW~
Thank you so much !!!
:D