1

I have a Logstash cluster (8 machines) I use to parse a huge amount of data every morning. I want to automate the launching step of my process. To do this, I have a master I use to send commands to all the machines on my cluster. But here is my problem : I want to do everything from the master and for that I have to remotely execute a script and this script needs a parameter (a date) and I don't know how to pass this argument through the ssh + 'bash -s' < my_script.sh command

ssh -i something.pem user@ip 'bash -s' < start_logstash.sh $1

The start_logstash.sh script needs the $1 param to work and obviously the previous command doesn't work... This ssh command is included in a for loop that execute command on every machine I specified.

EDIT : I found a kind of "quick win" for my problem. I use this command in the initial script (not the start_logstash.sh) :

sed -i -r "s/([0-9]){8}/$1/g" start_logstash.sh

This set the date variable in my script where $1 is obviously the argument I passed to principal.sh. But I'm always looking for a more sexy way to do it using ssh directly

Quentin
  • 435
  • 2
  • 6
  • 15
  • This is not an exact duplicate of [How to execute a remote command over ssh with arguments?](http://stackoverflow.com/q/18502945/4154375). In this case the commands to be executed are not fixed, they are in a script that is on the local machine. The answers to the supposed duplicate question do not answer this question. – pjh Nov 28 '16 at 16:17
  • Thank you for your support, I was making some precisions in my question ! But I've said it, this is not a duplicate question. EDIT : I corrected the title (more explicit right now) – Quentin Nov 28 '16 at 16:21
  • @Kuaaaly: What is wrong with your attempt then? A bit of tweak as `ssh -i something.pem user@ip "bash -s" -- < start_logstash.sh "$1"` should do the trick for you – Inian Nov 28 '16 at 16:36
  • See http://stackoverflow.com/questions/37262215/command-line-parameters-in-bash-shell-script-in-nested-ssh as another arguable duplicate. – Charles Duffy Nov 28 '16 at 16:54
  • BTW, `ssh -i something.pem user@ip 'bash -s' < start_logstash.sh $1` is just a less-compatible way to write `ssh -i something.pem user@ip 'bash -s' $1 < start_logstash.sh`; there is absolutely no difference whatsoever between them. – Charles Duffy Nov 28 '16 at 16:55
  • @Kuaaaly, I don't read the answer question marked as duplicate as *requiring* commands to be "fixed" or hardcoded; that's *definitely* not true of the second arguable-duplicate linked from my comment above (first half of the accepted answer, as the second half is specific to that question's OP's specific situation). Could you be more clear about why these don't help you? – Charles Duffy Nov 28 '16 at 17:01

0 Answers0