I'm running macoS Ventura (13.1). Bash is my default shell. Please bear with me - I am still a shell noob.
I have a shell script stored in a file on my system. I can successfully run the shell script from the Terminal:
sh ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/cronjob_test.sh
After several unsuccessful runs I have stripped out some of the code to simplify it - still no joy though. Here is the simplified script:
#! /bin/bash
DEVICE_NAME="MBP "
# Get battery percent charge
BATTERY_PERCENT=55
# Append to log
timestamp() {
date +"%Y-%m-%d %H:%M:%S"
}
TIMESTAMP=$(timestamp)
echo "$TIMESTAMP,$DEVICE_NAME,$BATTERY_PERCENT,Cronjob Test" >> ~/crontab_log.csv
exit 0
A new csv row is added to crontab_log.csv when I run the script as above. But when I try to call this script from crontab I get an error, this is from mail
:
bin/bash: /Users/nadnosliw/Documents/4 Project Folders/Shell Script Project Files/cronjob_test.sh: Operation not permitted
If you are able to help me fix this it would be awesome! Thanks for reading.
Below are my unsuccessful attempts to call the script from crontab (every 4 hours):
0 */4 * * * bash ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/battery_check.sh
0 */4 * * * bin/bash ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/battery_check.sh
0 */4 * * * sh ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/battery_check.sh
0 */4 * * * ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/battery_check.sh
I was hoping that the script would be executed and a new row of data added to my csv file.
Per this question [https://stackoverflow.com/questions/31217026/shell-script-my-crontab-script-does-not-run] I have also tried:
chmod +x ~/Documents/4\ Project\ Folders/Shell\ Script\ Project\ Files/cronjob_test.sh
- changing script to just this :-
#! /bin/bash
echo "running"
Still receive same error:
sh: /Users/nadnosliw/Documents/4 Project Folders/Shell Script Project Files/cronjob_test.sh: Operation not permitted