的文件users.yml
回用awk数组包含多个用户名和密码。一些用户名和密码正在重复。例如...
xxxxx
username: abc
password: abcpwd
xxxxx
xxxxx
username: adam
password: adampwd
xxxxx
xxxxx
username: adam
password: adampwd
xxxxx
脚本文件script.sh
是试图让所有文件从users.yml
用户名的条件相匹配的行号。
username='adam'
filepath='/etc/myServer/users.yml'
#Gets the line number for the username
userNameLineNumbers=`awk -v line='^.*username: '$username'' '$0~line {print NR}' $filepath`
echo "username line number: "$userNameLineNumbers #output: username line number: 6 10
如果我在users.yml
所在的同一台机器上运行脚本,该脚本工作正常。然而,问题是...
问题
如果我继续脚本另一台服务器上和脚本不起作用尝试从文件中获得的行号远程。
我尝试了几种方法来使用ssh
来获得行号,但无法做到这一点。我不是bash脚本编写的专家,但仍以不同的方式尝试以下命令,每次都会给出一些奇怪的结果,而不是从文件中给出行号。
script="sudo awk -v line='^.*username: '$username'' '$0~line {print NR}' $filepath"
userNameLineNumbers=$(ssh -o "StrictHostKeyChecking no" -tty -i "$PEM_FILE" "[email protected]" $script)
期望的输出
寻找的溶液,以获得行号从文件其中awk
的标准相匹配的远程服务器上的阵列。
也许尝试使用'SSH -t' ... –
@l” 'l','nope'ssh -t'也没有帮助 – wafers
回复:“没有帮助”......它有什么作用? –