0

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

ssh [email protected] "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 [email protected] "find ~/listfile/ -iname \"*log*\""

How do I see the content of files found?

αғsнιη
  • 40,939
  • 15
  • 71
  • 114
  • 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 – roaima 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.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
αғsнιη
  • 40,939
  • 15
  • 71
  • 114
  • 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