Using pipe and ssh to connect commands between different unix hosts. Output local cat, less, etc into remote files. Grep or watch remote logsBy neokrates, written on November 26, 2010
Ever wanted to grep through the remote file like you do on your local host? Log in and logout just to check the server config may be avoided. Many Linux / unix commands let you to connect local STDOUT to remote STDIN or vice versa. Here are some use cases which may make your life simpler.
✔ most Linux distros
✔ unix systems
Your user has public / private key pair without pass phrase.
So, you can execute remote commands without any interaction.
Write local output into remote file
You just installed the apache on your
$myhost. Now you want to test it.
echo the test string into file, only this time the file is in remote htdocs root:
echo "It works" | ssh firstname.lastname@example.org 'cat >> /usr/local/apache/htdocs/it_works.html'
Then you open the browser and should see http://$myhost/it_works.html
Open remote file with
ssh email@example.com "cat /usr/local/apache/htdocs/it_works.html"
ssh firstname.lastname@example.org "less /usr/local/apache/htdocs/it_works.html"
Grep remote files
ssh email@example.com "cat /usr/local/apache/htdocs/it_works.html" | grep "works"
Just remote grep:
ssh firstname.lastname@example.org "grep works /usr/local/apache/htdocs/it_works.html"
Watching remote logs with
This way you can watch the access to apache server in real-time:
ssh email@example.com "tail -f /etc/httpd/logfiles/access_log"
Have fun! ;)
INCOMING SEARCH TERMS