Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的脚本:
if rsh $server grep "string" /usr/path/file.txt then echo "yes" else echo "no" fi
基本上我想检查远程服务器中包含一些特定字符串的文件。无论我放入“字符串”中,它都不起作用并且总是显示“是”。
但是,如果我删除“rsh $server”,这意味着在本地运行,并将该文件放入本地,它工作正常。
有谁知道问题是什么?如何修改我的脚本?
您可以grep使用远程文件中的数据在本地运行:
grep
if rsh $server cat /usr/path/file.txt | grep "string" then echo "yes" else echo "no" fi
如果文件很大,这会很慢,因为整个文件必须通过网络发送,以便本地grep可以读取它。