启动时启动perl脚本 [英] Launch perl script on startup

查看:219
本文介绍了启动时启动perl脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试启动一个应该在启动时一直运行的perl脚本。



我正在使用CentOS服务器



我在 /etc/rc.d/rc.local 中添加了此行在我从控制台键入同一行时,脚本将无法启动:

  perl / svcmon / bin / svcperf。 pl --svc fav01svc --interval 5> / dev / null& 

此脚本实际上应该启动,您必须等待数据插入您的数据库,但添加

 >> / dev / null /& 

允许您在脚本在后台工作时继续使用您的计算机。



我真的不知道我能做什么,因为我不知道为什么它不工作...



你知道我可以尝试什么吗?



编辑:原来,我设法通过这样做启动我的脚本:



nohup / usr / bin / perl /svcmon/bin/svcperf.pl --svc fav01svc --interval 5> /outputsvcperf.txt&



但它不工作,因为PostgreSQL服务器没有及时启动,在启动时和我的perl脚本之前启动...

解决方案


  1. (命令工作的地方)键入命令: which perl



    这将产生一个输出, strong>完整路径到perl二进制。让我们说例如它在你的rc.local脚本中返回 / bin / perl


  2. <将perl your-command更改为/ bin / perl your-command(基本上用完全限定名称替换Perl)。 (帽子/提示@choroba在注释中注意)。



    这是因为,在你的命令行上,你有一个 $ PATH 设置,这让你的Unix shell找到驻留在路径中的命令。当RC脚本运行时,它们没有为shell设置PATH,因此不知道在哪里搜索commmands。


  3. 顺便说一下,这可能不是问题,但将>> / dev / null 更改为> / dev / null


参考文献:




I'm currently trying to launch a perl script that is supposed to run all the time on startup.

i'm working on a CentOS server.

I added this line in /etc/rc.d/rc.local and the script won't start while it works when I type the same line from the console :

perl /svcmon/bin/svcperf.pl --svc fav01svc --interval 5 >> /dev/null &

This script is actually supposed to be launched and you have to wait for as many time as you want datas inserted in your database, but adding

>> /dev/null/& 

allows you to keep on using your machine while the script is working in background.

I don't really know what I could do because I don't get why it doesn't work...

Do you have any idea of what I could try ?

EDIT : It turns out that I managed to launch my script properly by doing this :

nohup /usr/bin/perl /svcmon/bin/svcperf.pl --svc fav01svc --interval 5 > /outputsvcperf.txt &

but it doesn't work because the PostgreSQL server isn't launched in time while it is supposed to be launched on startup and before my perl script...

解决方案

  1. In your Unix shell (where the command works) type the command: "which perl"

    This will produce an output giving a full path to perl binary. Let's say for example it returns "/bin/perl"

  2. In your rc.local script, change "perl your-command" to "/bin/perl your-command" (basically replace Perl with the fully qualifying name). (hat/tip @choroba for noticing in comments).

    This is because, on your command line, you have a $PATH set up, which lets your Unix shell find commands that reside in the path. When RC scripts run, they don't have a PATH set up for them by the shell, and therefore don't know where to search for commmands.

  3. Incidentally, this likely is NOT a problem, but change ">>/dev/null" to ">/dev/null". You don't append to a null device, you output to it.

References:

这篇关于启动时启动perl脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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