So I am going to ask for something major here and that is if I can scan from one device all other connected devices to see if they have a specific line of text in any of their files.

It is a bit like using the grep -rl "text to find" "file location" command but that does it on one machine you are currently on. now what I am asking is having the machine I am on scan all other devices in the same folder for files containing the text that has to be found and if it does printing the machine name with the files containing the files like it does on one machine


This is how it does on one machine but now I hope it is possible to do it like this

machine name    /etc/firewall
machine name    /etc/network/interfaces

Or if it can even be done a bit nicer

machine name


I might be asking the impossible but I have seen ubuntu do the impossible before

update1: since I got a solution from Rinzwind I was able to get on certain machines but others had port 22 closed so still having that problem

update2: problem with the port has been solved by adding -p 220 between user@host and "grep in Rinzwind's solution



ssh user@host -p port "grep -rl 'help' /home/" >> /tmp/search.txt

will return any file inside /home that contains "help" on remote server {host} on {port} using {user} and add it to "/tmp/search.txt". This assumes {host} will accept {user} as a valid user and might prompt for passwords.

For this to work over multiple machines you could read a config file with users and hosts and iterate over them. It would probably be easier to do this in "python" or "perl" as you can easily manipulate and format the results on each pass and then write to stdout the results.

  • well all machines have a root account with the same name so that won't be a problem but i tried our code but my machine comes with the following root@pe-fw:~# ssh {root}@{host} "grep -rl '82.204.38' /etc/" >> /tmp/search.txt ssh: Could not resolve hostname {host}: Name or service not known' did i miss something or am i a complete idiot mind you still learning the ropes and all – delfiler May 7 '18 at 12:43
  • Change {host} for the actual hostname it is registered on your machine (or use an IP address ;) ) Drop the {} since those where to identify a variable in my code ;) – Rinzwind May 7 '18 at 12:51
  • okay so if i were to do the following ssh root@ "grep -rl '82.204.38' /etc/" >> /tmp/search.txt that should ask all those machines in the range right? – delfiler May 7 '18 at 12:55
  • If you want to query a large number of hosts you may find parallel-ssh (from package pssh) useful – steeldriver May 7 '18 at 13:01
  • @steeldriver okay so if i were to use pssh instead of ssh the resault would be the same correct? – delfiler May 7 '18 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.