Jump to content

Linux - Grep experts ki oka question


jefferson1

Recommended Posts

Na daggara oka script undi, adi Sudo search chesthundi couple of servers lo (on a particular folder) by taking a string from me (manual input) and displays results and tells me which sever has that string .

Ala search results lo vachina files ni automatic ga na laptop ki copy cheyocha?

 

 

 

Link to comment
Share on other sites

Nee office laptop through putty use chesi connect avuthava? If yes, you can copy all that files in to you a particular folder and zip them. Then through file zilla you can back to your laptop. Just nenu regular ga chese process cheppa, may be nee scenario different ayee undochu

Link to comment
Share on other sites

2 minutes ago, rajnik said:

try to pipe the scp command and see if that works

for that you have to sftp cheyali not ssh. Write another shell script, this new script should first search then sftp so its 2 step process 

Link to comment
Share on other sites

4 minutes ago, FLraja said:

for that you have to sftp cheyali not ssh. Write another shell script, this new script should first search then sftp so its 2 step process 

+1

Laptop lo ftp process run avvali.

Link to comment
Share on other sites

14 minutes ago, jefferson1 said:

Na daggara oka script undi, adi Sudo search chesthundi couple of servers lo (on a particular folder) by taking a string from me (manual input) and displays results and tells me which sever has that string .

Ala search results lo vachina files ni automatic ga na laptop ki copy cheyocha?

 

 

 

scp command to transfer files. if you want UI based , cyberduck of filezilla will do the task for you.

Link to comment
Share on other sites

17 minutes ago, jefferson1 said:

Na daggara oka script undi, adi Sudo search chesthundi couple of servers lo (on a particular folder) by taking a string from me (manual input) and displays results and tells me which sever has that string .

Ala search results lo vachina files ni automatic ga na laptop ki copy cheyocha?

 

 

 

If it's on a NAS then Mount the NAS to your Windows box.

Use Rsync

Use autosys file watcher and create a new file in a folder Every Time the string occurs and autosys will copy the file to your machine using scp. 

Use Tomcat and use the same file to check on UI.

Email the files if you have email on the linux host. 

So many options 

Link to comment
Share on other sites

1 hour ago, jefferson1 said:

Na daggara oka script undi, adi Sudo search chesthundi couple of servers lo (on a particular folder) by taking a string from me (manual input) and displays results and tells me which sever has that string .

Ala search results lo vachina files ni automatic ga na laptop ki copy cheyocha?

 

 

 

You must be using ssh remote command run option in your script. Just update your script to scp the files to the server from where your are running your script (laptop). Something like 

scp $user@$server:$(grep output from ssh) $absolutepath/$server-$filename 

Link to comment
Share on other sites

3 hours ago, jefferson1 said:

Na daggara oka script undi, adi Sudo search chesthundi couple of servers lo (on a particular folder) by taking a string from me (manual input) and displays results and tells me which sever has that string .

Ala search results lo vachina files ni automatic ga na laptop ki copy cheyocha?

 

 

 

Xargs+sftp/ftp does the job.

Link to comment
Share on other sites

Ok here is my requirement

 

i use putty to login into servers.

I login into Host A,

i wrote a script (script1) and made it executable. this script when executed will search for a string on Host B, Host C and Host D in a particular directory.

script execution will look like this :

user: ./script1 uniquestring *20200420* >output

 

Script is like this: less script1

S=$1

Y=$2

echo "$S"

ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

ssh HostC 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

ssh HostD 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

 

after the execution of the script, i will see the result in output file. this is now what i have

what i need is, if there is a file in the output, 

i need all those files to be copied to tmp/result directory

is this possible?

 

Link to comment
Share on other sites

14 minutes ago, jefferson1 said:

Ok here is my requirement

 

i use putty to login into servers.

I login into Host A,

i wrote a script (script1) and made it executable. this script when executed will search for a string on Host B, Host C and Host D in a particular directory.

script execution will look like this :

user: ./script1 uniquestring *20200420* >output

 

Script is like this: less script1

S=$1

Y=$2

echo "$S"

ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

ssh HostC 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

ssh HostD 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '

 

after the execution of the script, i will see the result in output file. this is now what i have

what i need is, if there is a file in the output, 

i need all those files to be copied to tmp/result directory

is this possible?

 

 
thumbnail.jpg?domain=www.electroappsmacs.com
Flash Player for Mac
Stream and View Video, Audio, Multimedia and Rich Internet Applications.
www.electroappsmacs.com
 
 

 

try to incorporate this in script

for file in $(ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTB:$file /tmp; done;

for file in $(ssh HostC  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTC:$file /tmp; done;

for file in $(ssh HostD  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTD:$file /tmp; done;

Link to comment
Share on other sites

1 hour ago, kumar4world said:

try to incorporate this in script

for file in $(ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTB:$file /tmp; done;

for file in $(ssh HostC  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTC:$file /tmp; done;

for file in $(ssh HostD  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '); do scp HOSTD:$file /tmp; done;

this didn't work for some resaon bro

correct format unte ivvu

Link to comment
Share on other sites

34 minutes ago, jefferson1 said:

this didn't work for some resaon bro

correct format unte ivvu

try with backticks:

for file in `ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTB:$file /tmp; done;

for file in `ssh HostC  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTC:$file /tmp; done;

for file in `ssh HostD  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTD:$file /tmp; done;

 

 

working for me:

 

for i in `ssh some_host 'grep -lr login /opt/logs/access/'`; do scp some_host:$i /tmp;done
access.log                                                                                                                                        100% 7298KB 106.4MB/s   00:00

Link to comment
Share on other sites

21 minutes ago, kumar4world said:

try with backticks:

for file in `ssh HostB 'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTB:$file /tmp; done;

for file in `ssh HostC  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTC:$file /tmp; done;

for file in `ssh HostD  'grep -l '$S' /opt/cmdapplication/logs.'$Y'* '`; do scp HOSTD:$file /tmp; done;

 

 

working for me:

 

for i in `ssh some_host 'grep -lr login /opt/logs/access/'`; do scp some_host:$i /tmp;done
access.log                                                                                                                                        100% 7298KB 106.4MB/s   00:00

small confusion.. here

you used "for files in" the beginning and later you used

"for i"... which is the correct one

Link to comment
Share on other sites

1 minute ago, jefferson1 said:

small confusion.. here

you used "for files in" the beginning and later you used

"for i"... which is the correct one

anything is fine, both are correct, its just a variable.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...