启动时启动perl脚本

编程入门 行业动态 更新时间:2024-10-13 18:24:52
本文介绍了启动时启动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脚本之前启动...

解决方案

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

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

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

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

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

  • 参考文献:

    • serverfault/questions/268674/why-does-rc-local-require-absolute-paths-how-can-i-run- a-script-at-startup-that
    • serverfault/questions/297527/how-to-test-etc-rc-d- rc-local-to-make-sure-a-command-will-start-successful-at
    • www.centos/docs/5/html/Installation_Guide -en-US / s1-boot-init-shutdown-run-boot.html

    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...

    解决方案

  • 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"

  • 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.

  • 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:

    • serverfault/questions/268674/why-does-rc-local-require-absolute-paths-how-can-i-run-a-script-at-startup-that
    • serverfault/questions/297527/how-to-test-etc-rc-d-rc-local-to-make-sure-a-command-will-start-successfully-at
    • www.centos/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-run-boot.html

    更多推荐

    启动时启动perl脚本

    本文发布于:2023-11-25 15:10:05,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1630241.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:启动时   脚本   perl

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!