EDIT:My script is located at $HOME folder.This is the reason of the issue.More details by the end of the question.In any case,this is not a duplicate question!
I have a quite trivial script deleting some log files.Running perfectly from command line. However,If I install it on crontab,sporadically I get
/bin/sh: 1: $MyScript.sh: not found
I thought that might be related with crontab config so I have installed it into crontab specifically for my user via
sudo vi /etc/crontab
Unfortunately I still keep getting the same error intemittently. Below is my script.
#!/bin/sh
NOW=$(date +"%m-%d-%Y-%T")
echo "$NOW Starting deleting of log files"
find /$PATH_TO_DIR/logs/* -mtime +30 -type f -delete
if [ $? -eq 0 ]
then
echo "$NOW Successfully deleted files"
else
echo "$NOW Could not delete files"
fi
Any help appreciated.
EDIT: Issue was my home folder being encrypted.That is why it was intemittently working,only when I was logged in to terminal.(Then home folder is decrypted and my schript is found). So I moved my script to somewhere else and it started working.