linux - 为什么当我尝试远程执行命令时出现错误?
问题描述
我有一个关于通过 SSH 远程执行命令的问题。我在下面尝试。
ssh xx.xx.xx.xx "psql -U qradar -c "select count(id) from offense_view where to_timestamp(start_time/1000) > NOW() - interval '180 minutes'"
它给出了一个错误,如:
Pseudo-terminal will not be allocated because stdin is not a terminal. ERROR: syntax error at or near "180" LINE 1: ... to_timestamp(start_time/1000) > NOW() - interval 180 minute...
解决方案
问题是您使用双引号来分隔命令内部的参数ssh
和参数psql
。这会导致您的字符串被错误地解析。您还缺少psql
命令的结尾双引号。
在 shell 中嵌套引号很棘手,使用ssh
. 如果您使用 here-doc 会更容易。
ssh xx.xx.xx.xx <<EOF
psql -U qradar -c "select count(id) from offense_view where to_timestamp(start_time/1000) > NOW() - interval '180 minutes'"
EOF
推荐阅读
- bash - 如何调用awk来处理/var/log/wtmp?
- r - 什么 R 对象可以保存变量,以便我可以迭代该对象?
- android - 具有在线数据的最简单的应用程序,(android)
- javascript - Returning an object in an function expression - is null
- excel - 使用 2 个条件创建 vlookup 或索引匹配
- javascript - 获取最小值和最大值
- laravel - 拉拉维尔 | groupBy 作为对象返回
- python - Python 从tripadvisor 抓取“要做的事情”
- php - 数组未定义的偏移量注意 if 条件 [php]
- javascript - Javascript/Node.js 内部如何表示函数?