手动运行时,cron作业工作,但不能从crontab中 [英] Cron job works when run manually, but not from crontab

查看:143
本文介绍了手动运行时,cron作业工作,但不能从crontab中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个使用永远控制node.js的一个脚本,它没有任何幻想,但我想它的时候手动运行,但是从cron作业@reboot什么也不会发生在运行时它的工作就是这个样子,我有cron的集到stderr和stdout重定向到一个日志文件,这样我就可以揣摩出来,但该文件永远不会改变。

I made a script that uses forever to control node.js, its nothing fancy, but it works just the way I want it to when run manually, however when run from the Cron job @reboot nothing happens, I have the cron set to redirect stderr and stdout to a log file so I can try to figure it out, but the file never changes.

cron作业:
     @reboot / sbin目录/ Ghost启动和放大器;> /home/mary/.ghost.log

脚本的内容:

#!/bin/bash

###########################################################
# This script is made to control Ghost using forever as   #
# if it were a service running on your system. Place in   #
# your path ie /usr/bin/                                  #
#                                                         #
# This script was created/tested on a Rasberry Pi         #
# running Raspbian, however it should be *NIX independent #
#                                                         #
# This script must be run as root, sudo will not work     #
# with forever                                            #
#                                                         #
# Make sure you alter the GhostDIR variable to your       #
# ghost directory, ie mine is /opt/ghost                  #
#                                                         #
# Created by Paul Williams                                #
# www.infinitepercent.com                                 #
###########################################################

# Variables:
GhostDIR=/opt/ghost #BE SURE TO ADJUST THIS TO YOUR GHOST DIRECTORY


# Functions:

# start function will test if Ghost is running, if not it will start it with forever
start()
{
    PID=$(ps -ef | grep monitor\ index.js | grep -v grep | grep -v ps | awk '{print $2}')
    if [ "$PID" = "" ]; then
        NODE_ENV=production forever start index.js
    else
        echo "Ghost is already running!"
    fi
}

# stop function will test if Ghost is running, it if is it will stop it with forever
stop()
{
    PID=$(ps -ef | grep monitor\ index.js | grep -v grep | grep -v ps | awk '{print $2}')
    if [ "$PID" = "" ]; then
        echo "Ghost isn't running!"
    else
        forever stop index.js
    fi
}

# restart function calls stop function and then calls start function
restart()
{
    stop
    start
}

# WARNING, DO NOT EVER MANUALLY ENTER BOOT
# YOU MAY END UP WITH MULTIPLE INSTANCES OF GHOST
# THIS OPTION IS MEANT TO BE USED FOR A CRON @REBOOT
boot()
{
    NODE_ENV=production forever start index.js
}

# status function is used to check on the status of Ghost
status()
{
    forever list
}

cd $GhostDIR

if [ "$1" = "start" ]; then
    start
elif [ "$1" = "stop" ]; then
    stop
elif [ "$1" = "restart" ]; then
    restart
elif [ "$1" = "status" ]; then
    status
elif [ "$1" = "boot" ]; then
    boot
else
    echo "$0 {start|stop|restart|status}"
fi

任何帮助AP preciated!

Any help is appreciated!

推荐答案

典型的cron错误。

您必须使用绝对路径的一切。即使是grep的,PS,AWK等。

You must use absolute paths for everything. Even for grep, ps, awk, etc.

这篇关于手动运行时,cron作业工作,但不能从crontab中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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