I've written a short bash script to record the temperature of my Pi which I'll schedule in cron to run every 15 mins and output to a file on my desktop called readings.txt
The problem is the command needs sudo privileges to run. So my question is how do I enable automatic entry of the password into the command within the script?
#!/bin/bash
sudo vcgencmd measure_temp >> ~/Desktop/readings.txt
sudo crontab -eto schedule a cron job at root. – user68186 Mar 20 '21 at 14:09sudo crontab -ethe command you put in is executed by not you DaveP, but a different user whose name isroot. Sincerootwill execute script, you don't needsudo vcgencmdinside your script. Now~refers to the home folder of the user. If the user is you, DaveP then your home folder is at/home/davep/. Therefore the absolute path to that~/Desktop/folder is/home/davep/Desktop/. – user68186 Mar 22 '21 at 20:36rootexecutes the command, or you schedule it in cron on behalf ofrootby usingsudo crontab -e, then the "home" folder forrootis/root/. Now you don't want your filereadings.txtin/root/Desktop/folder. So you need to put the absolute path for the filesreadings.txtas/home/davep/Desktop/readings.txt. You may also need to put the absolute path for/path/to/vcgencmdas cron environment has only a few paths set by default. – user68186 Mar 22 '21 at 20:37