且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过SSH在远程服务器上运行awk comand

更新时间:2023-12-05 14:08:40

在发送脚本之前,awk变量在本地扩展为shell变量.引用here文档定界符以按原样发送here文档.

The awk variables are expanded as shell variables locally before the script is sent. Quote the here document delimiter to send the here document as-is.

(此外,摆脱命令替换,而直接将其写入文件即可.)

(Also, get rid of the command substitution and just write directly to the file.)

#!/bin/ksh

sshpass -p password  ssh -T user@ip -q << 'EOF' > Request.txt
find /opt/Info_Source/*daily* -type f -mtime -1 -exec zcat {} \; 2>/dev/null | 
awk -F, '$5 ~ /Valid/ && length($2) {print $2}'
EOF