0

I have requirement to connect to remote machine and then get info and pipe to while loop.

ssh rao@172.168.1.123 "find ~/listfile/ -iname \"*log*\" |while read line; do cat $line; done"

The above commands is printing empty lines. I tried find itself to check command and it does works and list files.

ssh rao@172.168.1.123 "find ~/listfile/ -iname \"*log*\""

How do I see the content of files found?

αғsнιη
  • 41,407
  • 1
    I would have escaped the $ in cat $line inside loop. – Archemar Sep 20 '17 at 14:42
  • 1
    "The above commands is printing empty lines." it is likely also to be writing error messages about files not being found, as you're reading local file names based on a remote list – Chris Davies Aug 22 '21 at 08:26

1 Answers1

1

You should use find alone if you are going to list files with matched name where you ssh in remote server and add only if files -type f.

ssh USER@HOST 'find ~/listfile/ -type f -iname "*log*" '

If you need to cat the content of the files found, use find with cat as follows.

ssh USER@HOST 'find ~/listfile/ -type f -iname "*log*" -exec cat {} +'

Your particular problem is that $line is expanded by the local shell as it's in double quotes. But any way, your apprach is a wrong way to loop over find's results. See Why is looping over find's output bad practice? for details.

αғsнιη
  • 41,407
  • thanks for Quick answer. Here my requirement is to find the files in remote machine and display the content of the files.

    i.e the reason i am using the CAT command

    – venkata rao Sep 20 '17 at 05:21