首页 > 解决方案 > 将脚本运行到远程计算机时出现问题

问题描述

我通过 ssh 将脚本运行到远程机器:

ssh -p$port $user@$ip "bash /dati/bin/add_data.sh $t_ext_aria $t_pannello $t_ext_muro $t_cantina $t_bollitore $t_PT $t_P1 $t_P2 $H_PT $H_P1 $H_P2"

脚本 add_data.sh (在远程机器中)的内容非常不言自明:运行一个 mysql 查询,传递 11 个参数:


query="INSERT INTO temp (t_ext_aria , t_pannello , t_ext_muro , t_cantina , t_bollitore , t_PT , t_P1 , t_P2 , H_PT , H_P1 , H_P2) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,${10},${11})"
echo $query >> debug.log
mysql --user=rf --password=password tana << EOF
$query;
EOF

一切正常,除了它没有在 debug.log 中记录任何内容(我需要记录以调查为什么有时 mysql 查询失败:可能是一些错误的格式数据)

但是如果我登录到远程机器并从那里运行脚本:例如

bash add_data.sh 1 1 1 1 1 1 1 1 1 1 1

它正确写入 debug.log 。

我放了 777 许可以避免任何问题。

我哪里错了?

谢谢的工厂

标签: bashssh

解决方案


推荐阅读