Reputation: 21
I have added a script in /etc/sudoers
file.
user ALL=(ALL) NOPASSWD:/home/user/project/execute.sh
After that I have added the same script in users crontab as shown below:
*/1 * * * * /home/user/project/execute.sh > /home/user/cronjob-logs/`date +\%FT\%T`-cron.log 2>&1
There is a command in the script which can only be run using sudo
. But since I added the script in sudoers file, it works in the terminal without password. But it throws "permission denied" error in crontab. Can anyone please help? Thanks in advance.
Upvotes: 1
Views: 1912
Reputation: 21
I was able to solve the issue by adding sudo before the script in crontab as shown below:
*/1 * * * * sudo /home/user/project/execute.sh > /home/user/cronjob-logs/date +\%FT\%T-cron.log 2>&1
Upvotes: 1