Author Topic: Cron scripts not getting executed (cronie)  (Read 4840 times)

0 Members and 1 Guest are viewing this topic.

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Cron scripts not getting executed (cronie)
« on: 09. May 2016, 04:30:15 »
Manjaro comes with Cronie, which is an implementation of cron with which you can run cron jobs.

In /etc the are some folders like cron.hourly. When you put a script in there as root, those scripts should get executed every hour. However they don't. At least not in my case. But I don't know why.

My script is set to be executable, so that's not the issue.

Anyone got any ideas?

Offline badbodh

  • Held Mitglied
  • *****
  • Posts: 923
  • Windows assumes I'm stupid, Linux proves it.
  • Branch: Testing
  • Desktop: Xfce, i3
  • GPU Card: Intel Mobile 4 Series
  • Kernel: linux41 64-bit
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #1 on: 09. May 2016, 04:51:12 »
we will if you show us your script :)
You can't feel the love till it hurts a little. Go rolling, go bleeding-edge !

Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #2 on: 09. May 2016, 08:41:02 »
i have noticed the same thing a while ago.
i have not found a solution, but a workaround. i am also interested in a proper solution.


i want to run commands as root inside cron, so i do the following:
Code: [Select]
put all your cronjobs into a file /.crontab:
* */7 * * * yaourt -Sy
next, execute this command (and every time you changed the content of /.crontab file):
sudo crontab /.crontab -u root
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline badbodh

  • Held Mitglied
  • *****
  • Posts: 923
  • Windows assumes I'm stupid, Linux proves it.
  • Branch: Testing
  • Desktop: Xfce, i3
  • GPU Card: Intel Mobile 4 Series
  • Kernel: linux41 64-bit
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #3 on: 09. May 2016, 10:49:25 »
everything cron amigos http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

then show us the command you're running with cron. Maybe command is faulty. Silly typo, or syntax.
You can't feel the love till it hurts a little. Go rolling, go bleeding-edge !

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #4 on: 09. May 2016, 13:00:06 »
we will if you show us your script :)

I made a simple script to test things, so I don't think the script is the issue. Like Excalibur said, I think the system in Manjaro to execute cron job scripts might be broken.


Code: [Select]
#!/bin/bash

notify-send 'This is a test title' 'This is a test message'


Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #5 on: 09. May 2016, 13:05:23 »
i have noticed the same thing a while ago.
i have not found a solution, but a workaround. i am also interested in a proper solution.


i want to run commands as root inside cron, so i do the following:
Code: [Select]
put all your cronjobs into a file /.crontab:
* */7 * * * yaourt -Sy
next, execute this command (and every time you changed the content of /.crontab file):
sudo crontab /.crontab -u root

That didn't seem to work. This is my .crontab file:

Code: [Select]
*/1 * * * * root run-parts /etc/cron.minutely #Runs a cron job every minute
01 * * * * root run-parts /etc/cron.hourly #Runs a cron job every hour
02 4 * * * root run-parts /etc/cron.daily #Runs a cron job every day
22 4 * * 0 root run-parts /etc/cron.weekly #Runs a cron job every week
42 4 1 * * root run-parts /etc/cron.monthly #Runs a cron job every month

For testing purposes I put my test script that runs the notification message in the cron.minutely folder.


Offline excalibur1234

  • Global Moderator
  • *****
  • Posts: 2508
  • Branch: unstable
  • Desktop: net-minimal + LXQt
  • GPU driver: video-nouveau
  • Kernel: 4.6
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #6 on: 09. May 2016, 13:56:01 »
i think i did not make myself clear enough. here again a description what i am doing:

1. create the file /.crontab. if this file already exists, create a file  /.crontab2 instead and change all the following commands accordingly.
2. edit the file /.crontab with your script to start. in your case it could be:
Code: [Select]
*/1 * * * * notify-send 'This is a test title' 'This is a test message'
3. run the following command in your terminal:
Code: [Select]
sudo crontab /.crontab -u root
in your case, you probably do not need the "-u root" part, because your command does not need root privileges to run. but you should test this!
4. reboot your system.
5. now, you should see a notification every minute (if you have notify-send installed and configured correctly).
Need more information? Search here:   Manjaro Forum   |   Manjaro Wiki   |   Arch Wiki

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #7 on: 09. May 2016, 14:36:14 »
i think i did not make myself clear enough. here again a description what i am doing:

1. create the file /.crontab. if this file already exists, create a file  /.crontab2 instead and change all the following commands accordingly.
2. edit the file /.crontab with your script to start. in your case it could be:
Code: [Select]
*/1 * * * * notify-send 'This is a test title' 'This is a test message'
3. run the following command in your terminal:
Code: [Select]
sudo crontab /.crontab -u root
in your case, you probably do not need the "-u root" part, because your command does not need root privileges to run. but you should test this!
4. reboot your system.
5. now, you should see a notification every minute (if you have notify-send installed and configured correctly).

That didn't work either, so I ran the following command to see what was actually happening:

Code: [Select]
journalctl -xb -u cronie
The output from that was:

Code: [Select]
crond[726]: (notify-send) ERROR (getpwnam() failed)
It could be a bug, because I googled 'ERROR (getpwnam() failed)' and it brought me here: https://bugzilla.redhat.com/show_bug.cgi?id=1209600

It seems that over at Redhat they had the same issue, however their error message also mentions a broken pipe, which is different from my error message.

So I'm not sure if it's really a bug, but it could be.
« Last Edit: 09. May 2016, 15:02:34 by Heart Of A Lion »

Offline scachemaille

  • Held Mitglied
  • *****
  • Posts: 528
  • I'm new. Be nice!
  • Branch: Unstable
  • Desktop: Plasma 5
  • GPU Card: nVidia GT 330M
  • GPU driver: Nouveau
  • Kernel: 4.8_x64
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #8 on: 09. May 2016, 15:51:59 »
in my case I tried to just add a script in the hourly folder in /etc and it works.
my test was just to echo a string in a file.

just something weird is that if I try to put this file in /tmp it seems to doesn't work without any error reported.

and if you execute send-notify with root privilege you won't receive any notification as you're not root


EDIT: I tried to add some script in my own crontab running as my user.
the script is executed correctly. but notify-send don't work.
maybe it's missing some environment variable in cronie to display it on screen.
« Last Edit: 09. May 2016, 16:14:45 by scachemaille »

Offline badbodh

  • Held Mitglied
  • *****
  • Posts: 923
  • Windows assumes I'm stupid, Linux proves it.
  • Branch: Testing
  • Desktop: Xfce, i3
  • GPU Card: Intel Mobile 4 Series
  • Kernel: linux41 64-bit
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #9 on: 09. May 2016, 16:12:13 »
hmm. Valid point with notify-send. Try echoing something stupid into a txt file instead. Like time. So you know when the cron is running.
Code: [Select]
* */6 * * * timedatectl > badtime.txt see if it runs every 6 hours
You can't feel the love till it hurts a little. Go rolling, go bleeding-edge !

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #10 on: 09. May 2016, 16:16:33 »
in my case I tried to just add a script in the hourly folder in /etc and it works.
my test was just to echo a string in a file.

just something weird is that if I try to put this file in /tmp it seems to doesn't work without any error reported.

and if you execute send-notify with root privilege you won't receive any notification as you're not root


EDIT: I tried to add some script in my own crontab running as my user.
the script is executed correctly. but notify-send don't work.
maybe it's missing some environment variable in cronie to display it on screen.

Running anything else other than send-notify doesn't seem to work for me either. When I try to simply run galculator via a cron job in the same way that I tried to run send-notify, then also Galculator didn't run, but when I execute that same command in a terminal, it works fine.

Offline scachemaille

  • Held Mitglied
  • *****
  • Posts: 528
  • I'm new. Be nice!
  • Branch: Unstable
  • Desktop: Plasma 5
  • GPU Card: nVidia GT 330M
  • GPU driver: Nouveau
  • Kernel: 4.8_x64
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #11 on: 09. May 2016, 16:19:54 »
Running anything else other than send-notify doesn't seem to work for me either. When I try to simply run galculator via a cron job in the same way that I tried to run send-notify, then also Galculator didn't run, but when I execute that same command in a terminal, it works fine.
I think nothing graphical will work as crond launch a new session with pam but certainly without any display.
in your script , write in a file after launching galculator, you will see your file is created.
or try to export the display in your script.

Code: [Select]
export DISPLAY=:0
« Last Edit: 09. May 2016, 16:23:57 by scachemaille »

Offline Heart Of A Lion

  • Sr. Mitglied
  • ****
  • Posts: 313
  • I'm new. Be nice!
  • Branch: Stable
  • Desktop: Xfce, Enlightenment
  • GPU Card: ATi 7770 . . . . . . . CPU: AMD octacore 4GHz
  • GPU driver: Free (video-ATI)
  • Kernel: 4.6 (x64)
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #12 on: 09. May 2016, 16:28:05 »
hmm. Valid point with notify-send. Try echoing something stupid into a txt file instead. Like time. So you know when the cron is running.
Code: [Select]
* */6 * * * timedatectl > badtime.txt see if it runs every 6 hours

For some reason, that does seem to work, which is puzzling. Why do some commands work and others not?

Offline scachemaille

  • Held Mitglied
  • *****
  • Posts: 528
  • I'm new. Be nice!
  • Branch: Unstable
  • Desktop: Plasma 5
  • GPU Card: nVidia GT 330M
  • GPU driver: Nouveau
  • Kernel: 4.8_x64
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #13 on: 09. May 2016, 16:42:29 »
For some reason, that does seem to work, which is puzzling. Why do some commands work and others not?
like as I told you. if you want to launch graphical program you have to export the display in your script.
Code: [Select]
export DISPLAY=:0I tried with and without exporting it and try to launch "konsole" from my script. and it works only if I export the screen.

for an unknown reason notifiy-send doesn't work even with exporting the display. I guess it miss something else for this command to send the notification to the current user session.


there is an other problem, it's if for I don't know why the display number change. (I'm not an Xorg expert )
« Last Edit: 09. May 2016, 16:47:10 by scachemaille »

Offline badbodh

  • Held Mitglied
  • *****
  • Posts: 923
  • Windows assumes I'm stupid, Linux proves it.
  • Branch: Testing
  • Desktop: Xfce, i3
  • GPU Card: Intel Mobile 4 Series
  • Kernel: linux41 64-bit
  • Skill: Intermediate
Re: Cron scripts not getting executed (cronie)
« Reply #14 on: 09. May 2016, 16:57:00 »
if just exporting display not good enough. You need to authorize root to use <user>'s display.
Code: [Select]
xhost + [something]https://www.x.org/archive/X11R6.8.0/doc/xhost.1.html

Then launch a graphical app using
Code: [Select]
dbus-launch <command>
« Last Edit: 09. May 2016, 16:58:46 by badbodh »
You can't feel the love till it hurts a little. Go rolling, go bleeding-edge !