Answer the question
In order to leave comments, you need to log in
The command in the bash script does not work, where is the error?
One of the commands in the script does not run when setting a task in cron
00 09 * * * /mnt/pve/backups/sensors.sh >> /root/myscript.log 2>&1
13-Oct-2021 09:00
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +29.0В°C (high = +84.0В°C, crit = +100.0В°C)
Core 0: +26.0В°C (high = +84.0В°C, crit = +100.0В°C)
Core 1: +26.0В°C (high = +84.0В°C, crit = +100.0В°C)
Core 2: +23.0В°C (high = +84.0В°C, crit = +100.0В°C)
Core 3: +23.0В°C (high = +84.0В°C, crit = +100.0В°C)
acpitz-acpi-0
Adapter: ACPI interface
temp1: +27.8В°C (crit = +119.0В°C)
temp2: +29.8В°C (crit = +119.0В°C)
/mnt/pve/backups/sensors.sh: line 9: hddtemp: command not found
#!/bin/bash
date=`date +%d-%b-%Y%t%H:%M`
echo -e "\n$date\n" >> sensors.txt
sensors >> sensors.txt
hddtemp /dev/sda >> sensors.txt
hddtemp /dev/sdb >> sensors.txt
hddtemp /dev/sdc >> sensors.txt
Answer the question
In order to leave comments, you need to log in
hddtemp /dev/sda >> sensors.txt
hddtemp /dev/sdb >> sensors.txt
hddtemp /dev/sdc >> sensors.txt
You need to look at PATH not from your session, but directly from cron.
When a user logs in interactively, his personal profiles are executed - .profile, .bashrc, .login, etc.
Cron just runs with the rights of the specified user, without reading his profiles.
Options for how to fix this:
1. Use full paths to files in scripts
2. Set PATH directly in your script
3. Set PATH in the crontab itself at the beginning, for example
PATH=$PATH:/home/user/mypersonalbin/
00 09 * * * /mnt/pve/backups/sensors.sh >> /root/myscript.log 2>&1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question