简体   繁体   English

SSH 从 crontab (Nagios) 执行 PHP 脚本的问题

[英]SSH Issue executing a PHP script from crontab (Nagios)

i have an issue executing a PHP Script (chmod 777 nagios:nagios) as CRON.我在将 PHP 脚本(chmod 777 nagios:nagios)作为 CRON 执行时遇到问题。

The sh command inside the PHP script is the following: PHP 脚本中的 sh 命令如下:

ssh nagios@$host /backup/nagios/counter.sh

The problem is, when i run the PHP script in my local host with:问题是,当我在本地主机上运行 PHP 脚本时:

./counter_script.php 172.28.39.138

The result is showing fine on PuTTY if i run like that, but when i add the script to the crontab like:如果我这样运行,结果在 PuTTY 上显示良好,但是当我将脚本添加到 crontab 时,如下所示:

*/5 * * * * /usr/local/nagios/homemade/counter_script.php 172.28.39.138 > /usr/local/nagios/homemade/outputest.txt

the Script wont run the remote SH and the test.txt file say Cant Connect to Remote host.脚本不会运行远程 SH 并且 test.txt 文件说无法连接到远程主机。

So the output in Nagios Portal is displaying a Connection Issue status too.所以 Nagios 门户中的 output 也显示了连接问题状态。

I can connect via SSH directly to/from both Host in PuTTY.我可以通过 SSH 直接与 PuTTY 中的两个主机连接。 I copied the public keys like always with this command using nagios user:我像往常一样使用 nagios 用户使用此命令复制了公钥:

ssh-copy-id -i /home/nagios/.ssh/id_rsa.pub nagios@172.28.39.138

Someone told me it is a SSH Authority issue but i cant fix it yet, any help will be great:)有人告诉我这是一个 SSH 授权问题,但我还不能修复它,任何帮助都会很棒:)

*/5 * * * * /usr/local/nagios/homemade/counter_script.php 172.28.39.138 > /usr/local/nagios/homemade/outputest.txt. */5 * * * * /usr/local/nagios/homemade/counter_script.php 172.28.39.138 > /usr/local/nagios/homemade/outputest.txt。 try to keep your ssh key in new file f, and copy the ur ssh key (ssh-copy-id -i /home/nagios/.ssh/id_rsa.pub nagios@172.28.39.138) give file permission for that file in chmod 700, and remove ur ip and give this file name there.尝试将您的 ssh 密钥保留在新文件 f 中,并复制您的 ssh 密钥(ssh-copy-id -i /home/nagios/.ssh/id_rsa.pub nagios@172.28.39.138 为该文件授予权限) 700,然后删除你的 ip 并在那里给出这个文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM