Ruby on rails “如何打印”;“早上好”;每天早上9点到控制台

Ruby on rails “如何打印”;“早上好”;每天早上9点到控制台,ruby-on-rails,ruby,cron,Ruby On Rails,Ruby,Cron,我想用crontab编写一个每天早上9点运行的程序,它将打印出消息“早上好,Cam” 以下是我目前正在尝试的: Crontab: 5 * * * * /Users/cameronbass/Desktop/Play/Ruby/hello_world.rb 节目: Puts "Good Morning, Cam" 来自cron的错误消息: /bin/sh: /Users/cameronbass/Desktop/Play/Ruby/hello_world.rb: Permission denied

我想用crontab编写一个每天早上9点运行的程序,它将打印出消息“早上好,Cam”

以下是我目前正在尝试的:

Crontab:

5 * * * * /Users/cameronbass/Desktop/Play/Ruby/hello_world.rb
节目:

Puts "Good Morning, Cam"
来自cron的错误消息:

/bin/sh: /Users/cameronbass/Desktop/Play/Ruby/hello_world.rb: Permission denied

使用Ruby可以吗?

您试图在没有执行权限的情况下运行脚本。如果crontab以cameronbass的形式运行,则只需执行以下操作:

cd /Users/cameronbass/Desktop/Play/Ruby/
chown cameronbass hello_world.rb # set cameronbass as an owner
chmod 700 hello_world.rb # give read, write and execute permissions to owner

然后重试。

您试图在没有执行权限的情况下运行脚本。如果crontab以cameronbass的形式运行,则只需执行以下操作:

cd /Users/cameronbass/Desktop/Play/Ruby/
chown cameronbass hello_world.rb # set cameronbass as an owner
chmod 700 hello_world.rb # give read, write and execute permissions to owner

然后重试。

脚本的权限不正确。
ls-l/Users/cameronbass/Desktop/Play/Ruby/hello_world.rb的输出是什么?尽管如此,重要的是要理解,您不会看到任何输出。Cron将在另一个会话中运行您的脚本,您将看不到它的输出
put
而不是
put
。后者将引发
NameError:uninitialized constant put
。要在终端中查看它,您必须执行类似“wall”的操作早上好,Cam“`脚本的权限不正确。
ls-l/Users/cameronbass/Desktop/Play/Ruby/hello_world.rb的输出是什么?尽管如此,重要的是要理解,您不会看到任何输出。Cron将在另一个会话中运行您的脚本,您将看不到它的输出
put
而不是
put
。后者将引发
NameError:uninitialized constant Puts
。要在终端中看到它,您必须执行类似“wall”的操作早上好,Cam“`虽然这将解决权限问题,但不会解决输出未出现在用户控制台上的问题。虽然这将解决权限问题,但不会解决输出未出现在用户控制台上的问题。