L
L
lumino42014-04-04 19:04:21
linux
lumino4, 2014-04-04 19:04:21

Why doesn't the script run via crontab -e as a user?

Ubuntu Linux distribution 13.10

* * * * * agent /bin/bash /home/agent/rails_projects/project/rake_script.sh 2> /home/agent/errors

Without cron the script works
With crontab -e (or crontab -e -u agent) error:
/bin/sh: 1: agent: not found
Strange because:
agent:x:1000:1000:agent,,,:/home/agent:/bin/bash
in /etc/passwd
I tried and write in /etc/crontab (no results) :
* * * * * agent sh /home/agent/rails_projects/project/rake_script.sh 2> /home/agent/errors

The script must be run as the user.
The script itself:
#!/bin/bash
cd /home/agent/rails_projects/project
bundle exec rake db:alarm

Tell me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2014-04-04
@lumino4

You cannot specify a user in a cron job. There can only be a command line. The word agent is interpreted as a command that does not exist.
Also, be prepared that when you run the script this way, the value of $PATH will be different from what you see in the interactive session, and you will need to additionally do . /etc/profile or . ~/.bash_profile.

V
Vlad Zhivotnev, 2014-04-04
@inkvizitor68sl

You do not need to specify a user in crontab -e. Just
remove the space after 2>. If you are going to do it through -e, then add the user to /etc/cron.allow
Then do chmod +x /home/agent/rails_projects/project/rake_script.sh and write to cron like this:

# если в crontab -e, то
* * * * * /home/agent/rails_projects/project/rake_script.sh 2>home/agent/errors

# если в /etc/cron.d/sth или /etc/crontab, то
* * * * * agent /home/agent/rails_projects/project/rake_script.sh 2>home/agent/errors

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question