I'm using Bourne Shell: #!/bin/sh
I'm doing a script that find a file/s that match a specific pattern and while the command is executing, copy every output to a new directory.
myscript.sh
#!/bin/sh
ssh user@hostname find /path/to/find/file* -mtime 10 | while read -r LINE
do
scp -r user@hostname:$LINE /path/to/destination/
done
That's my initial script to find the files with the same filename pattern but there are some other files that don't have the same filename pattern. So I decided to use grep and pipe it to find but it doesn't read the ssh anymore instead it finds the files in the current directory which clearly doesn't exist.
Here's an example:
ssh user@hostname find /path/to/find/* -mtime 10 | xargs zgrep -il 'pattern_to_find' | while read -r LINE
do
    scp -r user@hostname:$LINE /path/to/destination/
done
See I wanted to use this command find /path/to/find/* -mtime 10 | xargs zgrep -il 'pattern_to_find' but when I incorporate it with a while using | it doesn't work fine anymore.


