-1

I want to run a script that checks if the specific folder exists on a remote server then greps a specific line from a specific file in that server to the local machine.

if ssh -t -t user@server [ -d /etc/nginx ]; then
      ssh -t -t  user@server 
ls -1a /etc/nginx/conf.d | grep $1 | xargs cat | grep specific_line | grep  .specific-extension | awk '{print $2}'
fi 

I use awk '{print $2}' to print out the second line of the grepd line

SO I want this to be an output in my local machine or even better I want to put that in a variable in the script.

I haven't find anything on the internet that solves even the simplified version of this.

I have PSK enabled on the servers so I don't have to enter the password when I ssh.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
CzipO
  • 89
  • 1
  • 6
  • Don't use grep to process `ls` output -- see [ParsingLs](http://mywiki.wooledge.org/ParsingLs) – Charles Duffy Jun 10 '19 at 15:43
  • ...anyhow, can you provide any more details about what you're trying to accomplish? I'd hazard that *all* your `grep`/`cat`/etc. could be replaced with a single remote `find ... -exec awk` command. – Charles Duffy Jun 10 '19 at 15:44

1 Answers1

-1

I just did something similar using paramiko in Python. I test the sudo privileges of many accounts over hundreds of IPs in a few minutes. You can run the command and get stdin, stdout, and stderr. That should get you started in the right direction

You can use logins and certs with it too if that helps.

ThatCampbellKid
  • 561
  • 1
  • 5
  • 19