You are not logged in.

#1 2023-10-19 19:36:43

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Script does not work all the way through in cron

This script works when manually started, works when started by Xfce Application Autostart at boot, but stops part way through in a cron job:

#!/bin/sh

sleep 6s
killall -u $(id -nu) conky 2>/dev/null
cd "$HOME/.conky"
conky -q -c "$HOME/.conky/BL-Cal-mod3.conkyrc" &
cd "$HOME/.conky/MX-MyConky"
conky -q -c "$HOME/.conky/MX-MyConky/MySysInfoConky" &
exit 0

It kills the running conkys and quits.
MX Linux 21 Xfce version.

Offline

#2 2023-10-19 23:09:22

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Script does not work all the way through in cron

@ jeffreyC

Trim the fat a little:

#!/bin/sh
sleep 6
killall conky
conky -c $HOME/.conky/BL-Cal-mod3.conkyrc &
conky -c $HOME/.conky/MX-MyConky/MySysInfoConky &
exit 0

See if that works.

Question: Why wait 6 seconds?


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#3 2023-10-20 00:23:50

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Re: Script does not work all the way through in cron

Sector11 wrote:

@ jeffreyC

Trim the fat a little:

#!/bin/sh
sleep 6
killall conky
conky -c $HOME/.conky/BL-Cal-mod3.conkyrc &
conky -c $HOME/.conky/MX-MyConky/MySysInfoConky &
exit 0

See if that works.

Question: Why wait 6 seconds?

The 6 second wait is for the desktop to come up before the conkys at boot.

Still would need the -q switches in the conky starts, otherwise the .xsession-errors adds a line every second which makes it grow and grow...
It wasn't so OCD in Stretch but Bullseye and Bookworm log everything.

Offline

#4 2023-10-20 03:36:01

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Script does not work all the way through in cron

OK, understood about -q
no idea why it doesn't finish in a cron job.  sad

GUGL pointed out a few things:

There could be several reasons why a script scheduled in Crontab is not running. Here are some common issues you can check:

    Check that the Crontab entry is correct. Make sure you have specified the correct path to the script and that the syntax is correct.

Don't use

$HOME

use

/home/username/

    Check the permissions of the script. Ensure that the script has the correct permissions to be executed by the user running the Cron job.

    Check the system time. Ensure that the system time is correct, as Cron relies on the system time to schedule jobs.

This looks interesting too:
    Check the user's environment variables. Cron jobs do not run with the same environment variables as the user who scheduled the job. You may need to specify environment variables within the Crontab entry or within the script itself.

IF that's right try changing

conky -q -c $HOME/.conky/......

to

conky -q -c /home/username/.conky/BL-Cal-mod3.conkyrc &

    Check the system logs. Check the system logs for any errors related to Cron or the script.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#5 2023-10-20 03:45:25

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Script does not work all the way through in cron

Might be something here: top reasons your cron job isnt running


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#6 2023-10-20 09:50:28

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,640

Re: Script does not work all the way through in cron

So the script doesn't work with the -q switch?
But without the -q switch?

It just fills your .xsession-errors? And why a cron job?

Then kill this file that no one needs. There are several possibilities for that.

Offline

#7 2023-10-21 06:13:36

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Re: Script does not work all the way through in cron

With your modified script (plus the -q switch) it still runs the killall part and then fails to start the conkys again.

If it was a script permission problem it would not run at all.
If the path to the script was not correct it would not run at all.

The same script runs all the way when started manually.

Last edited by jeffreyC (2023-10-21 06:22:35)

Offline

#8 2023-10-21 09:47:15

PackRat
jgmenu user Numero Uno
Registered: 2015-10-02
Posts: 2,611

Re: Script does not work all the way through in cron

jeffreyC wrote:

If the path to the script was not correct it would not run at all.

Did you change $HOME to /home/user_name like S11 suggested?

$HOME is correct for your user environment so the script will run to completion when you launch it manually. $HOME is not correct for a cron job (ambiguous). The script may be looking in /root as $HOME for the cron job.


You must unlearn what you have learned.
    -- yoda

Offline

#9 2023-10-22 04:44:22

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Re: Script does not work all the way through in cron

PackRat wrote:
jeffreyC wrote:

If the path to the script was not correct it would not run at all.

Did you change $HOME to /home/user_name like S11 suggested?

$HOME is correct for your user environment so the script will run to completion when you launch it manually. $HOME is not correct for a cron job (ambiguous). The script may be looking in /root as $HOME for the cron job.

Yes, I changed the path to the script.
Did not change the paths in the script to where the conkys were located, they were the parts that did not work, will try that.

Offline

#10 2023-10-22 06:01:38

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Re: Script does not work all the way through in cron

jeffreyC wrote:
PackRat wrote:
jeffreyC wrote:

If the path to the script was not correct it would not run at all.

Did you change $HOME to /home/user_name like S11 suggested?

$HOME is correct for your user environment so the script will run to completion when you launch it manually. $HOME is not correct for a cron job (ambiguous). The script may be looking in /root as $HOME for the cron job.

Yes, I changed the path to the script.
Did not change the paths in the script to where the conkys were located, they were the parts that did not work, will try that.

Still fails.

Offline

#11 2023-10-22 07:40:36

rbh
Moderator
From: South of Lapplands inland
Registered: 2016-08-11
Posts: 1,921

Re: Script does not work all the way through in cron

PackRat wrote:

$HOME is correct for your user environment so the script will run to completion when you launch it manually. $HOME is not correct for a cron job (ambiguous). The script may be looking in /root as $HOME for the cron job.

You can use variables like $HOME in scripts managed by cron. If user PackRat is owner of the cronjob, the variabel will be expanded to /home/PackRat. If root is the owner, the expanded location will be /root.

Variables in scripts, saves a lot of typing... Do not stop using them...


// Regards rbh

Please read before requesting help: "Guide to getting help", "Introduction to the Bunsenlabs Lithium Desktop" and other help topics under "Help & Resources" on the BunsenLabs menu

Offline

#12 2023-10-22 08:59:06

rbh
Moderator
From: South of Lapplands inland
Registered: 2016-08-11
Posts: 1,921

Re: Script does not work all the way through in cron

On my server, I have a cronjob starting att boot. The command has flag: " -logfile=$HOME/.config/..."". command ps -ef shows: " -logfile=/home/rbh/.config/..."

Just for the fun of it, I createed a cronjob for rbh. Running :
@hourly $HOME/tmp/printenv.sh

The script is:
===
#!/bin/sh

cd $HOME/tmp
printenv > printenv-from-cron.txt
===

I printed the environment from my bash and dash promt and compared with the environment from the cronjobb.
The cronjobs environment were more sparce than I had anticipated, but comon to them all was:

USER=rbh
HOME=/home/rbh
PWD=/home/rbh/tmp

The path is very sparce for the cronjobb:
"PATH=/usr/bin:/bin"
If you need to have path to $HOME/bin and $HOME/.local/bin, you have to expand the path in the script.

Last edited by rbh (2023-10-22 09:00:35)


// Regards rbh

Please read before requesting help: "Guide to getting help", "Introduction to the Bunsenlabs Lithium Desktop" and other help topics under "Help & Resources" on the BunsenLabs menu

Offline

#13 2023-10-22 09:32:58

rbh
Moderator
From: South of Lapplands inland
Registered: 2016-08-11
Posts: 1,921

Re: Script does not work all the way through in cron

I tested running a user cronjobb from webmin.
Omited -q flag from script killing running conkys and starting new.

Webmin has an ouput window for the command.
I got message: "can't open display: ".


// Regards rbh

Please read before requesting help: "Guide to getting help", "Introduction to the Bunsenlabs Lithium Desktop" and other help topics under "Help & Resources" on the BunsenLabs menu

Offline

#14 2023-10-22 10:50:46

rbh
Moderator
From: South of Lapplands inland
Registered: 2016-08-11
Posts: 1,921

Re: Script does not work all the way through in cron

rbh wrote:

I got message: "can't open display: ".

Worked when I added the below line as second line in the script:

export DISPLAY=:0.0


// Regards rbh

Please read before requesting help: "Guide to getting help", "Introduction to the Bunsenlabs Lithium Desktop" and other help topics under "Help & Resources" on the BunsenLabs menu

Offline

#15 2023-10-22 16:22:37

jeffreyC
Member
Registered: 2019-09-07
Posts: 192

Re: Script does not work all the way through in cron

If I do not have the -q switches in the conky-startup script it adds a line to the .xsession-errors every single second.
.xsession-errors logging is broken in recent Debian releases and they do not care to fix it.
https://salsa.debian.org/xorg-team/xorg … requests/7

Last edited by jeffreyC (2023-10-22 16:25:15)

Offline

#16 2023-10-22 16:53:42

rbh
Moderator
From: South of Lapplands inland
Registered: 2016-08-11
Posts: 1,921

Re: Script does not work all the way through in cron

jeffreyC wrote:

If I do not have the -q switches in the conky-startup script it adds a line to the .xsession-errors every single second.

I omitted -q flagg just for debugging purpose...

Have you tried adding line "export DISPLAY=:0.0"?


// Regards rbh

Please read before requesting help: "Guide to getting help", "Introduction to the Bunsenlabs Lithium Desktop" and other help topics under "Help & Resources" on the BunsenLabs menu

Offline

#17 2023-10-22 17:38:24

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,640

Re: Script does not work all the way through in cron

jeffreyC wrote:

If I do not have the -q switches in the conky-startup script it adds a line to the .xsession-errors every single second.
.xsession-errors logging is broken in recent Debian releases and they do not care to fix it.
https://salsa.debian.org/xorg-team/xorg … requests/7

the soft way
Have logrotate trim weekly or daily and keep max. two versions

sudo nano -w /etc/logrotate.d/xsession

$HOME/.xsession-errors {
  rotate 2
  weekly
  compress
  missingok
  notifempty
}

the hard tour
in autostart script

#!/bin/sh
if [ ! -h /home/user/.xsession-errors ]; then
	rm /home/user/.xsession-errors
	ln -s /dev/null /home/user/.xsession-errors
fi

user = jeffreyC

Offline

Board footer

Powered by FluxBB