Why isn’t my cron job executing the sed command?

0
6
Asked By CleverMango77 On

I'm running Debian 13 (Trixie) with KDE Plasma 6.3.6, and I'm trying to create a cron job that automatically switches the background of konsole between light and dark modes. Here's what I've written:

`0,15,30,45 18-23 * * * if [[ $(grep "konsoleLight" ~/local/share/konsole/SolarizedLight.colorscheme) ]]; then sed -i "s/konsoleLight/konsoleDark/g" ~/local/share/konsole/SolarizedLight.colorscheme; fi`

`0,15,30,45 8-17 * * * if [[ $(grep "konsoleDark" ~/local/share/konsole/SolarizedLight.colorscheme) ]]; then sed -i "s/konsoleDark/konsoleLight/g" ~/local/share/konsole/SolarizedLight.colorscheme; fi`

The problem is that the sed command doesn't seem to be executing when triggered by cron. When I run the same if statement in an interactive shell, it works fine. I've also confirmed that cron is active using `sudo service crond status` and by creating a simple job that outputs to a file every minute: `* * * * * echo "working" > ~/cron.out`. Why isn't the sed command working in my cron job?

2 Answers

Answered By SlickGiraffe94 On

It looks like the issue might be related to using the tilde (~) for your home directory in cron. Cron runs in a different environment, and it may not interpret the tilde as your home path. Try replacing `~` with the full path to your home directory, like `/home/yourusername`. That should help the sed command be executed correctly.

Answered By SwiftAardvark82 On

I had a similar issue before! After changing to the full path, make sure that your cron job has the correct permissions to modify the file. Check if the user running the cron job has write access to `~/local/share/konsole/SolarizedLight.colorscheme`. If it doesn't have the right permissions, the sed command won't run.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.