我想创建一个脚本,其中我可以从远程服务器的特定路径 grep 特定单词,并在输出中显示整个 grep 句子。
目前,我必须访问目标服务器,然后进入特定路径,然后使用 grep 命令。
#!/usr/bin/ksh
clientID="00000"
print -n "\nEnter the ID (Enter ybr for ybr_ybrfndt): $1"
read clientID
print "$clientID"
for HOST in $(cat qa_servers.txt ) ;
do
ssh $HOST "uname -a"
cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA
grep $clientID resources.xml;
done
答案1
该脚本应该适用于您的用例。
#!/usr/bin/ksh
print -n "\nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt