【发布时间】:2016-10-02 18:16:43
【问题描述】:
谁能解释一下如何使用 cPanel 管道选项来运行 ruby 脚本?基本上我想在每次收到电子邮件时运行一个 ruby 脚本。然后我想使用电子邮件中的数据在脚本中做一些事情。
在 pipe_test.rb 脚本内部,我正在尝试这样的事情:
email_data = STDIN.read
# Get email address
#....
# Do somthing with the email address
#...
更新 #1
在阅读了更多内容后,我可以通过运行ruby pipe_test.rb test 让这个脚本在 shell 中运行。
email_data = ARGV[0]
# Save data to a file
File.open("test_pipe_data.txt", 'w') { |file| file.write(email_data) }
# Get email address
#....
# Do somthing with the email address
#...
但是,当我将脚本添加到 cPanel 中的“管道到程序”文件路径选项时,它似乎并没有运行该脚本。我尝试添加以下文件路径选项组合,但均无效:
home/pipe_test.rb
home/pipe_test.rb test
home/ruby pipe_test.rb test
home/ruby ‘pipe_test.rb test’
home/‘ruby pipe_test.rb’
home/‘ruby pipe_test.rb test’
更新 #2
看起来我的问题的一部分是我需要在我的脚本顶部添加一个 Shebang 行,以便 shell 知道使用什么程序来运行脚本。所以我把它加到最上面一行:
#!/usr/bin/env ruby
我通过运行确认这是正确的路径:
which ruby
然后我打算将./pipe_test.rb cPanel 管道添加到程序路径。现在的问题是,当我从 shell 运行 ./pipe_test.rb 时,它说:
: No such file or directory
我已经运行echo $PATH 以确保该路径存在并且确实存在。所以我又被困住了。
【问题讨论】: