You are not logged in.
Pages: 1
Hello ,
I am trying to add job in crontab but after alot of googling I think I am missing some configurations related to (environment variables), and I really got lost reading and applying with no luck at least to know what exactly I am missing, the script works just fine by executing from terminal but adding to crontab it does not work, I am not sure if I am doing things wrong or I am missing more configurations.
I am using ArchLinux with i3-gaps, no Desktop Manager, cronie is installed and cronie.service is enabled.
the script is:
#!/bin/sh
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [ "$status" = Discharging -a "$capacity" -lt 50 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi
}("50" just for now in order to test the job)
and its placed in:
~/.bin >>> pwd
/home/wael/.binzsh is the default shell
~ >>> echo $SHELL
/bin/zshI have added the script path to the default path by adding the following line to ~/.zshrc:
export PATH=/home/wael/.bin:$PATH~ >>> echo $PATH
/home/wael/.bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perland the crontab is:
~ >>> crontab -l
* * * * * /home/wael/.bin/lowbattery.sh(every minute just for now in order to test the job)
its my first time dealing with cronie I am not sure if the infos are enough, so if more info should be provided let me know please.
Thanks
Offline
Your script is using /bin/sh to execute, not zsh. And since it is being executed from cron, the shell will be a non-interactive, non-login shell, which means that, even if you were using zsh, it wouldn't be initializing in the same way it does when you open a terminal, or log in to a tty. See 'man zsh' (or if you want to stick with sh, 'man bash' since on Arch, /bin/sh is provided by that).
Long story short, your PATH variable is likely unset. Set it manually in the script, or use full paths to executables.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Your script is using /bin/sh to execute, not zsh. And since it is being executed from cron, the shell will be a non-interactive, non-login shell, which means that, even if you were using zsh, it wouldn't be initializing in the same way it does when you open a terminal, or log in to a tty. See 'man zsh' (or if you want to stick with sh, 'man bash' since on Arch, /bin/sh is provided by that).
Long story short, your PATH variable is likely unset. Set it manually in the script, or use full paths to executables.
Thank you for the respond and the explanation, one question related to your answer
can I set both the shell and the path manually in the script?
Offline
Yes, of course. You can edit the script however you want.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Pages: 1