-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.

2
  • Don't use grep to process ls output -- see ParsingLs Commented Jun 10, 2019 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. Commented Jun 10, 2019 at 15:44

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.