0

I have an sh file with file-removing commands.

I run it from php like this:

shell_exec("sudo -n ./truncatefiles.sh  2>&1");

Thats works fine if I open the PHP file from browser, but doesnt work from scheduled cron tab.

PHP user: www-data

If i run whoiami from cron, returns same: www-data

I added this to my visudo:

www-data ALL=(ALL) NOPASSWD: /www/sites/..../importscript/truncatefiles.sh

Shell exec for this sh file returns (from cron):

sudo: sorry, a password is required to run sudo

Why works it dirrefent way in cron?

What should I do for get it work?

Bharat
  • 2,441
  • 3
  • 24
  • 36
bbenhu
  • 23
  • 4

1 Answers1

0

PLease try to do the following, Try to log your output from crotab to a file, * * myscript.php >> /var/log/myjob.log 2>&1 This way you can debug your script. 1. Also the check the user and permissions for your shell script, php file. 2. try with sudo crotab -e

Vineesh
  • 467
  • 4
  • 11