I've got the following bash script to check if a string length is nonzero using -n and equals "OK" by converting the variable to uppercase using ${1^^}:
#!/bin/bash
myfunction() {
result=0
if [[ -n $1 && ${1^^} = "OK" ]]; then
result=1
fi
echo $result >> /home/[REDACTED]/mylog
}
myfunction "ok"
myfunction "NO"
I made it executable using:
sudo chmod +x ./test
I then call it with either of the following:
bash ./test
./test
And the file always contains the expected result:
1
0
However, when trying to run from cron and the file contains:
0
0
I set up cron with this command:
sudo crontab -e
And here is the content:
* * * * * /home/[REDACTED]/test
I'm probably overlooking something obvious like syntax or cron environment... any suggestions?
Thanks!