I have a script like this:
if rsh $server grep "string" /usr/path/file.txt
then
echo "yes"
else
echo "no"
fi
Basically I want to check the file in remote server containing some specific strings. It doesn't work and always display "yes" whatever I put into "string".
However, if I remove "rsh $server", which means running locally, and put that file into local, it is working fine.
Does anyone know what the problem is? How can I modify my script?
You can run grep
locally with data from the remote file:
if rsh $server cat /usr/path/file.txt | grep "string"
then
echo "yes"
else
echo "no"
fi
This will be slow if the file is large, since the entire file has to be sent over the network so that the local grep
can read it.