User-Cron doesn't work

User Cron seems not to be executed.
I have this cron-jobs on user-level:

My CronTab looks like this:

Regarding to this Thread (Cron doesn't work) , I’ve checked that cronie is up and running:

Any Idea, what the issue might be?

And why there at least on systemctl status cronie > 2k entries of this brave-command:
image

Why do you believe that? You can see in your pictures (please do not post pictures of text) that something tried to open teams.
So it is clearly executed.

However, you might expect to see a Brave Browser Window and this will not be the case. It might be difficult to get a programm starting in your X session. You can check the Arch Wiki for some pointers. https://wiki.archlinux.org/title/cron#Running_X.org_server-based_applications

A systemd user timer might be easier and more reliable.

I remember trying to open a GUI via a cron job a couple of years ago and finding out that it is very difficult (i.e. almost impossible) to do, as cron has no idea what desktop environment you are using. This answer on Stack Exchange explains it much better than I can:

A basic Bash script (to start a GUI program) works partially in cron

cron jobs run in a completely separate environment, isolated from your usual GUI desktop or terminal environment.

firefox expects to be run as a child process of your desktop environment or, at the very least to have a valid DISPLAY variable set.

It is sometimes possible to get cron jobs to start or interact with GUI programs. Try adding export DISPLAY=:0.0 as the second line of your script. If :0.0 doesn’t work, run a terminal in your desktop and run echo $DISPLAY to get the correct value.

If this still doesn’t work, you may also need to set XAUTHORITY=$HOME/.Xauthority or maybe use xauth to enable access.

Note that any program started from cron (including firefox) will inherit cron’s fairly minimalist environment. Variables like PATH, LOGNAME and/or USER may be different to what you expect, and many variables won’t be set at all. e.g. the LC_* locale variables may not be set (depending on distro - e.g. cron in Debian reads /etc/environment and /etc/default/locale. I don’t know if that’s also the case on Fedora or not). If that program needs specific environment variables set to certain values, you’ll need to set them in your crontab file, or export them in your script too. Or just source your usual shell startup files from the script.

Firefox, Chromium, and other web browsers may need http_proxy, https_proxy and other proxy-related variables set…

xabbu’s recommendation of a systemd user timer might be more practical.

What are you trying to do?

What do you expect to happen?

When do you expect it to happen?

Alternatively, if you do not want to set up a systemd timer, you could add this script I just came up with (with a little help from Stack Exchange & Google) to autostart at login. It will run in the background and test the day, hour & minute every 30 seconds & launch Brave for you when the time matches. Another benefit over cron is that, if the Brave session opened by the script at 10:00am is still running at 10:40am, it won’t try to open another Brave session until the first Brave session is closed.

Note that I don’t have Brave browser installed on my system, so I tested it using Falkon, which didn’t require the full path to the program executable.

Anyway, here’s the script:

#!/bin/bash

# noncronscheduledjob - a startup alternative to using a cron script to run a command
# (especially open a GUI which cron cannot do)
# at minutes 00 and 40 past the hours 10 and 12 on Wednesdays.

declare -A arraydow=(
 [3]=1
) # DOW - day of week. Wednesday = 3rd day of week. To add more days just add more [*day number*]=1 items (eg [6]=1 for Saturdays)

declare -A arrayhod=(
 [10]=1 [12]=1
) # HOD - hour of day. Matches 10am & 12 noon. 24 hour time. To add more hours just add more [*hour*]=1 items (eg [02]=1 for 2am, [17]=1 for 5pm)

declare -A arraymoh=(
 [00]=1 [40]=1
) # MOH - minute of hour. To add more matching minutess just add more []=1 items

while true; do

DOW=$(date +%u) # Day number of week - 1 is Monday

echo "Day of week = ${DOW}" # can be removed or commented out

HOD=$(date +%H) # Hour of the day - 24 hour time, 2 digits

echo "Hour of day = ${HOD}" # can be removed or commented out

MOH=$(date +%M) # Minute of the hour - 00 to 59

echo "Minute of hour = ${MOH}" # can be removed or commented out

if [[ -n "${arraydow[$DOW]}" ]] && [[ -n "${arrayhod[$HOD]}" ]] && [[ -n "${arraymoh[$MOH]}" ]]; then

brave https://teams.microsoft.com/ #the command to be executed when the time matches.

fi

sleep 30; # will run the above test to match day & time every 30 seconds.

done

exit 0

Why try to re-invent the wheel?
Systsemd-timers aint hard to use…
You just need to read the man pages to learn the “new way” :wink:

Plus it will automatically have the “don’t run again when already running” functionality build-in…
Eg: systemd Timers start a service, which is not started again when that service is already running :wink:

Nice read for all of you: Restart plasmashell on a schedule: Cron? Systemd timer? Edit system file? - #17 by TriMoon as an answer to the post just above it. :stuck_out_tongue:


@rethus sorry i don’t answer image only issues…

1 Like

To be honest, I never heard about a systemd timer. I only know the cron-way.
Initially I’d only used the KDE onboard tools (means, I’ve looked in KDE-Settings for a scheduler and used it).
:slight_smile:

But good to know that there is something like an systemd timer.
Found systemdGenie as UI for KDE. Will give it a try

1 Like

Pleas purge that info from your memories, it’s prehistoric now :stuck_out_tongue:

I think I wrote the above script more as a challenge to myself to see if I could come up with something to schedule jobs without using cron, systemd or atd. I don’t actually use it myself (although I do have a couple of small scripts I use with “while true do…/sleep” etc to run every 15 seconds).

Anyway, I decided to heed your advice and dive into systemd timers. I do remember that I tried to create one some time ago & really struggled (possibly because the samples I was looking at were quite complicated - more for system admins than regular jobs to be run by a user), so I could never get it working. But today I decided to focus on user timers, and you are right - they are very easy to set up (if you have the right material to learn from - especially regarding OnCalendar time formatting).

So, the 3 personal cron jobs I had as well as 2 of my autostart jobs are now systemd-timer jobs:

So, thanks for giving me a little push TriMoon. I have some days where I focus really well, and many other days when my concentration is almost non-existent. Today I was focused, so it didn’t take me long at all to write the 5 timers.

Please*

And yeah, all hail systemd timers!

They make the world so much better. AND they’re easier to understand.

1 Like