Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give permission for the cron job file?

Tags:

crontab

I have set the cron tab for my site. But I have got message in my mailing id like this "Permission denied" for the script. Can anyone help me telling what may be the problem.

Thanks......

like image 520
user75472 Avatar asked May 21 '09 09:05

user75472


3 Answers

You get this error while setting the crontab? or from a script running from the cron?

If while setting the crontab, try this:

You type: crontab -e You get: -bash: /usr/bin/crontab: Permission denied

Problem: Your user is not in the cron group.

Solution: As root, edit the /etc/group file, find the cron group and add your user to that line (the usernames are comma-separated). Then re-login as your user.

Verify: Run command "groups". You should see "cron" in there.

(from http://www.parseerror.com/argh/crontab-e-Permission-denied.txt)

like image 176
Colin Pickard Avatar answered Oct 17 '22 10:10

Colin Pickard


friends if any one wants schedule crons from other user just do this

root user:-

ls /usr/bin/crontab
chmod 4755 /usr/bin/crontab

echo PATH
vi /etc/crontab

SHELL=/bin/bash
PATH=/usr/java/jdk1.5.0_22/bin:/root/bin:/usr/java/jdk1.5.0_22/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
MAILTO=root
HOME=/

cd /etc/cron.d

create cron.allow file if not exist

vi cron.allow
root
other username

save and exist

su – username
/usr/bin/crontab -e

schedule here ……………….

like image 28
ravi Avatar answered Oct 17 '22 10:10

ravi


I ran into this issue today and was baffled until I realized that the denied commands were SSH commands. I had forgotten that I was connecting with an SSH key that required a passphrase, so the real issue had nothing to do with cron in my case.

My solution was to create an additional key for this script with no passphrase (using ssh-keygen), install it on the remote server, and specify it in the script with the -i flag to the ssh commands.

ssh -i /path/to/id_rsa.no-passphrase user@remote command-to-run
like image 4
matt2000 Avatar answered Oct 17 '22 08:10

matt2000