0

I recently became a Sysadmin for the company I work for. One of the things I want to try and do is improve some of the processes with scripts. I am very new to bash but eager to learn and any help would be appreciated.

In my work if someone requests a grep we have to manually connect to the hostname and then become root and, after that perform the grep. This can be quite time consuming and so I started working on a script which would allow me to enter the following:

ssh user@hostname grep

The problem is I have no idea how to be able to connect to a given hostname. I would like some output when I run the script that asks me for the hostname which I type in and then asks me what I want to grep and from that I get my results.

Any help would be appreciated and apologies if this is a long winded post. It's my first time asking a question.

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
WeeZY
  • 1

1 Answers1

0

You can use the below command inside a script. $1 parameter could be the hostname and $2 the string to grep for, eg : myscript.sh host1 string_to_grep

ssh  user@${1} "grep \"${2}\" *"
nullPointer
  • 4,419
  • 1
  • 15
  • 27