Crontab and ruby script

#1

Hi all,

I used crontab command such as
“*/5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/script1.rb”

But it can’t execute script1.rb, I let it print some message every 5
min.

I also changed script1.rb to chmod 755.

Does the crontab command is right?

Thanks.

#2

Looks ok. I don’t think you need execute permission either, just read
permission would do, because you’re passing the file to the interpreter.

Verify that:
* Interpreter path is correct
* Program does not have errors and you are able to run it yourself
* It has correct permissions for accessing files etc as the user
you’ve setup the cron for
* If you’re just printing stuff remember it doesn’t have $stdout or
$stderr to write to, redirect those to some log file

Hope this helps

#3

You could also try using whenever

#4

I am quite noob
however…
if your script does use gui, maybe you must use
DISPLAY=:0.0
*/5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/script1.rb

a useful link may be
http://www.unix.com/answers-frequently-asked-questions/13527-cron-crontab.html

CC Chen wrote in post #1039530:

Hi all,

I used crontab command such as
“*/5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/script1.rb”

But it can’t execute script1.rb, I let it print some message every 5
min.

I also changed script1.rb to chmod 755.

Does the crontab command is right?

Thanks.

#5

On Jan 5, 2012, at 02:30 , CC Chen wrote:

Does the crontab command is right?

Run ‘env -i $SHELL --norc’. It will bring up a new naked shell that is
equivalent to what cron runs. Run your command as-is in this shell to
ensure it works correctly.

#6

Venkatakrishnan Ganesh wrote in post #1039547:

Looks ok. I don’t think you need execute permission either, just read
permission would do, because you’re passing the file to the interpreter.

Verify that:
* Interpreter path is correct
* Program does not have errors and you are able to run it yourself
* It has correct permissions for accessing files etc as the user
you’ve setup the cron for
* If you’re just printing stuff remember it doesn’t have $stdout or
$stderr to write to, redirect those to some log file

Hope this helps

Thanks,

I changed to

" */5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/script1.rb >>
/local/myuser/rubyscript/log.txt "

It find the message dump on log.txt, but does it can’t print out
directly??

#7

CC Chen wrote in post #1039530:

Hi all,

I used crontab command such as
“*/5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/script1.rb”

But it can’t execute script1.rb, I let it print some message every 5
min.

I also changed script1.rb to chmod 755.

Does the crontab command is right?

Thanks.

I write a script which it can link to ftp server and to download files.

I also used this command
"*/5 * * * * /usr/local/bin/ruby /local/myuser/rubyscript/ftpscript.rb

/local/myuser/rubyscript/ftplog.txt"

It just can dump ftplog.txt file but it can’t download any file from the
ftp server.

What should I do??

Thanks,

#8

Ryan D. wrote in post #1039638:

On Jan 5, 2012, at 02:30 , CC Chen wrote:

Does the crontab command is right?

Run ‘env -i $SHELL --norc’. It will bring up a new naked shell that is
equivalent to what cron runs. Run your command as-is in this shell to
ensure it works correctly.

So I add this command ‘env -i $SHELL --norc’ on crontab directly?

Thanks,

#9

On Fri, Jan 6, 2012 at 3:20 AM, CC Chen removed_email_address@domain.invalid wrote:

Ryan D. wrote in post #1039638:

On Jan 5, 2012, at 02:30 , CC Chen wrote:

Does the crontab command is right?

Run ‘env -i $SHELL --norc’. It will bring up a new naked shell that is
equivalent to what cron runs. Run your command as-is in this shell to
ensure it works correctly.

So I add this command ‘env -i $SHELL --norc’ on crontab directly?

No. This was intended for testing only.

Btw, you do not have those quotes at the beginning and end of the line
in your crontab, do you? If yes, you must remove them.

Kind regards

robert