0

I am installing Voipmonitor whose setup script has this step:

sudo echo " * * * * * root php /var/www/html/php/run.php cron" >> /etc/crontab

I am getting this error

-bash: /etc/crontab: Permission denied

The file permissions are:

-rw-r--r-- 1 root root 51 Feb 15 04:45 /etc/crontab
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
dnit13
  • 119

2 Answers2

4

The command does not work, because sudo applies to the command, however the redirection is made with the current user, and so it fails the permissions. So echo runs as root, however >> /etc/crontab is being done with the user permissions out of the sudo.

This will work:

sudo /bin/bash -c '( echo " * * * * * root php /var/www/html/php/run.php cron" >> /etc/crontab )'
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
2

You could use:

echo " * * * * * root php /var/www/html/php/run.php cron" | sudo tee -a /etc/crontab
Artur Szymczak
  • 1,933
  • 12
  • 12