2014-09-12 211 views
1

我试图用cron重新启动服务器。我发现这个链接:使用Cron的Shell脚本无法执行shell命令

https://help.openshift.com/hc/en-us/articles/202187644-Shell-scripts-using-Cron-or-action-hooks-can-t-execute-shell-commands

但不起作用。这是我的脚本:

#!/bin/bash 
source /usr/bin/rhcsh 
ctl_all restart 

而这种输出:

/usr/bin/rhcsh: line 7: source: filename argument required 
source: usage: source filename [arguments] 
/usr/bin/rhcsh: line 32: build_path: command not found 
/usr/bin/rhcsh: line 33: build_ld_library_path: No such file or directory 
    ********************************************************************* 
    You are accessing a service that is for use only by authorized users. 
    If you do not have authorization, discontinue use at once. 
    Any use of the services is subject to the applicable terms of the 
    agreement which can be found at: 
    https://www.openshift.com/legal 
    ********************************************************************* 
    Welcome to OpenShift shell 
    This shell will assist you in managing OpenShift applications. 
    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!! 
    Shell access is quite powerful and it is possible for you to 
    accidentally damage your application. Proceed with care! 
    If worse comes to worst, destroy your application with "rhc app delete" 
    and recreate it 
    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!! 
    Type "help" for more info. 
Command "quota" not found for app xxxxx, please check the node hosting this app 
WARNING: This ssh terminal was started without a tty. 
      It is highly recommended to login with: ssh -t 
Restarting services 
/usr/bin/rhcsh: line 123: gear: No such file or directory 

任何想法?

非常感谢。

编辑:

这里是rhcsh脚本(该脚本有300行,所以我上传到服务器):

http://www6.zippyshare.com/v/99209351/file.html

+0

似乎在/ usr/bin/rhcsh文件中出现了问题。你能粘贴它的内容吗? – 2014-09-12 16:37:58

+0

嗨Tomasz,问题在于cron安装在OpenShift(https://www.openshift.com)基础架构上,并且脚本无法修改。如果你仍然想看到脚本可以将其添加到主帖子。 – Alberto 2014-09-12 18:36:06

+0

仍然可能有帮助。这个问题可能不在脚本本身,而是在它使用的东西中,也许是一些环境变量。我特别好奇第一条错误发生在第7行的是什么。 – 2014-09-13 10:08:09

回答

1

试试这个:

#!/bin/bash 
gear restart --all-cartridges # same as: ctl_all restart 

ctl_all/usr/bin/gear脚本的包装函数。