0

All the google results mention cron jobs. They don't work, I followed multiple guides exactly, and the script is never launched.

I just need to set the brightness to change at morning and dusk, it seems like a pretty simple task to me, but it's surprising that I can't figure it out. I use brightnessctl to control the brightness of my laptop, and it does not require sudo.

I'm running Arch Linux. Installed cronie, in terminal I crontab -e, and in the file I write 41 17 * * * dunstify "timer", which is the time a few minutes after I wrote that, as a test to see if it runs.

I save the file, I enable and start the cronie service in systemctl, then type crontab -l, and there's "no crontab for indeedwatson".

EDIT: Crontab error: no crontab For [user]

This post led me to this command sudo crontab -u indeedwatson -e from which I can create a crontab that does show up for crontab -l. I don't understand why. I'm using sudo to create it, but not to list them, and in any case, all the guides do not require the -u flag, to me it seems implied by running it without sudo, it's my own user.

  • 1. Brightness of what? Do you have some home automation system controlled by your computer? 2. What operating system are you on? If it is a Linux system, please also tell us which distro and which distro release. Thank you! – Marcus Müller May 29 '23 at 15:56
  • 3. Is your system running continuously, or to modify that brightness actuator needs to be awoken from sleep or booted? – Marcus Müller May 29 '23 at 15:57
  • 1
    4. you say "I followed multiple guides exactly": well, we need to know what *exactly* you did, otherwise we won't be able to help. Please add the contents of what ever scripts, crontables or other things you did **to your question** by editing it! – Marcus Müller May 29 '23 at 16:02
  • 2
    Rather than engage in guess work, it would be best to edit your question to include the exact text of your `cron` job. – Seamus May 29 '23 at 16:07
  • 2
    Cron is rarely the right tool if what you want to do involves the graphical interface. Please [edit] your question, explain exactly what you want to achieve, on what operating system and what graphical environment, and we can try and help. It sounds like you just want something like http://jonls.dk/redshift/. – terdon May 29 '23 at 16:22
  • Did you ever check syslog whether crond tried to alert you, typically about permission requirements, syntax, and so on ? event if your crontask is silent, crond should speak in syslog. – Thibault LE PAUL May 29 '23 at 17:34
  • Does this answer your question? [Using notify-send with cron](https://unix.stackexchange.com/questions/111188/using-notify-send-with-cron) – roaima May 29 '23 at 21:46
  • I edited the question with more details @terdon I don't need a GUI. I use redshift for blue light filter, but its brightness control does not use the actual backlight. There is some script in the arch wiki about adding a hook to fix this, but it is not working either. – indeedwatson May 29 '23 at 21:52
  • I don't mean a GUI for the tool, I mean a graphical environment on your system: unless you are running Arch with no X and no desktop environment, you are using a GUI and this means that cron will need to interact with your X session. This is not impossible, it just adds significant complexity which is why I said cron is rarely the best tool for that kind of thing. Have a look at the link roaima posted just above:[Using notify-send with cron](https://unix.stackexchange.com/q/111188) – terdon May 29 '23 at 23:04

1 Answers1

0

Without knowing which Linux/Unix distribution you use, or what configuration changes you've made, or what command you've used in your cron job, it's tough to say for sure. I'll make some assumptions:

  1. Assuming that your brightness command actually works from the command line, and that it requires su privileges:

Instead of using the normal user crontab, use the root crontab; i.e. open your crontab for editing with sudo. In this way, your cron job will run with the required privileges:

sudo crontab -e
  1. Assuming you're not using a redirect to get the benefit of potentially helpful stderr & stdout, try that in your cron job; redirects are the >> to designate a file, and 2>&1 to include stderr and stdout :
...
0 7 * * * /full/path/to/bright-adj-pkg >> /home/user/mylog.txt 2>&1
0 19 * * * /full/path/to/bright-adj-pkg >> /home/user/mylog.txt 2>&1
...
Seamus
  • 2,522
  • 1
  • 16
  • 31