如何创建cron作业以运行ruby脚本? [英] how to create a cron job to run a ruby script?

查看:82
本文介绍了如何创建cron作业以运行ruby脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个cron作业来运行ruby脚本。这就是我放在crontab中的内容。

I want to create a cron job to run a ruby script. this is what i have put in the crontab.

2 * * * * ruby /home/mark/project/script.rb >> /home/mark/cronOutput.txt

但它没有运行。我认为cron以root身份运行时环境会出现问题。

But its not running. I think there's some problem with the environment getting loaded up when the cron runs as root.

请帮助。

推荐答案

如果您的红宝石不符合标准然后,我个人希望将路径保存在shell脚本中,从而确保所有路径等。正确设置我的ruby程序需求,并在crontab中安排脚本。做类似

If your ruby is in non standard paths then personally I like to wrap my ruby calls in a shell script, thereby ensuring that all the paths etc. my ruby program needs are set correctly, and schedule the script in crontab. Do something like

2 * * * * /home/mark/project/ruby_wrapper_sh >> /home/mark/cronOutput.txt 2>&1

和您的/ home / mark / project / ruby​​_wrapper_sh应该读取类似

and your /home/mark/project/ruby_wrapper_sh should read something like

#!/bin/bash

. ~mark/.bash_profile 
`ruby /home/mark/project/script.rb`

这篇关于如何创建cron作业以运行ruby脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆