在Ubuntu中启动时运行perl脚本

在Ubuntu中启动时运行perl脚本,perl,ubuntu,startupscript,Perl,Ubuntu,Startupscript,我有一个perl脚本,需要在启动时运行一次,在我的用户帐户下有一个参数 所以当我启动系统时,它需要执行这样的命令 ./path/to/script.pl start 有什么想法吗?取决于您正在使用的init,如果您的Ubuntu版本正在使用 如果没有,您必须配置相应的Upstart启动脚本 基于运行级别的rc脚本。选中更新rc.d您可以在crontab(crontab-e)中使用一行 要在启动时运行命令,请执行以下操作: 编辑/etc/crontab 添加以下行: @重新启动根perl./pa

我有一个perl脚本,需要在启动时运行一次,在我的用户帐户下有一个参数

所以当我启动系统时,它需要执行这样的命令

./path/to/script.pl start

有什么想法吗?

取决于您正在使用的
init
,如果您的Ubuntu版本正在使用

如果没有,您必须配置相应的Upstart启动脚本
基于
运行级别的
rc
脚本。选中
更新rc.d

您可以在crontab(crontab-e)中使用一行

要在启动时运行命令,请执行以下操作:

编辑/etc/crontab 添加以下行:

@重新启动根perl./path/to/script.pl start

^^^以root用户身份运行。将“root”更改为“BlackCow”以作为BlackCow运行

或者,您可以使用upstart(将.conf文件添加到/etc/init/)。这是我笔记中的一份拷贝和粘贴:

使用upstart在重新启动/启动时运行守护程序

e、 g./etc/init/prestaba.conf:

#!upstart
description "node.js server"
author      "BlackCow"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

script
    export HOME="/root"

    exec sudo -u root /usr/local/bin/node /home/prestocab/prestocab.com/www/socket.io/server.js 2>&1 >> /var/log/prestocab.log
end script
使用:

start prestocab
stop prestocab
restart prestocab
#
如果守护进程在Ubuntu上崩溃,您可能需要使用某种进程监视器来重新启动守护进程,最简单的方法是将这一行添加到您的
/etc/rc.local
文件中(在
退出0
行之前,用您自己的用户名替换
用户名
):

离题-试一试
su -c "./path/to/script.pl start" username &