Skip to main content
deleted 103 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

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.

Really need help and explanation for this one for me to fully understand what's wrong with my coding.

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.

Really need help and explanation for this one for me to fully understand what's wrong with my coding.

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.

Source Link

How to find a file matching a specific pattern and date while copying every found file to another web server's directory?

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.

Really need help and explanation for this one for me to fully understand what's wrong with my coding.