我想将错误和输出流重定向到/dev/null,我在脚本文件中使用了2>&1 /dev/null (如下所示),但我得到的错误是
"UPDATE 1
UPDATE 1
UPDATE 1
UPDATE 1
ERROR: syntax error at or near "EOF"
LINE 1: EOF 2>&1 /dev/null" ^如何重定向标准输出?
文件:
psql -h xx.xx.xx.xx -U postgres -d dbname
<<
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_id;
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_recovery_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_recovery_id;
EOF
2>&1 /dev/null发布于 2016-06-30 08:16:46
获得的错误消息是由于脚本中的语法错误造成的。
您所使用的此处文档需要使用<<EOF,而不仅仅是<<。
psql -h xx.xx.xx.xx -U postgres -d dbname <<EOF
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_id;
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_recovery_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_recovery_id;
EOF若要将输出从此重定向到文件:
psql -h xx.xx.xx.xx -U postgres -d dbname >outfile <<EOF
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_id;
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_recovery_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_recovery_id;
EOF也可以将错误流重定向到同一个文件:
psql -h xx.xx.xx.xx -U postgres -d dbname >outfile 2>&1 <<EOF
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_id;
update rhq_alert_condition set threshold = $critical_threshold where alert_definition_id = $critical_recovery_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_id;
update rhq_alert_condition set threshold = $warning_threshold where alert_definition_id = $warning_recovery_id;
EOF若要将错误流转到/dev/null,请改用2>/dev/null。
要让这两个流都转到位桶,请使用>/dev/null 2>&1。
发布于 2016-06-30 07:57:01
你可以这样做:
命令> /dev/null 2>&1
发布于 2020-07-20 23:28:14
我猜这个bash示例完成了作者询问的内容:
gnuplot -p << EOF > /dev/null 2>/dev/null
plot 'file.dat'
EOF我调用了gnuplot而不是psql,但是关于EOF和重定向的想法是一样的。
https://stackoverflow.com/questions/38116476
复制相似问题