0

I created this bash script to run python code on each host listed in my ip_list:

#!/bin/bash

declare -a ip_list=('10.99.1.1' '10.99.1.2' '10.99.1.3"' '10.99.1.4');

for i in $(ip_list) ; do 
    ssh -i ~/Downloads/abc.pem -t -t ec2-user@$i "sudo   python /home/user/abc.py"
done

But I got error:

Error: line 4: ip_list: command not found

What did I do wrong here? thanks

1
  • Use: for i in "${ip_list[@]}" ; do whereas $(ip_list) tries to run ip_list command Commented Jan 19, 2016 at 16:52

1 Answer 1

0

as @anubhava suggests, try ${ip_list[@]}, like this:

declare -a ip_list=('10.99.1.1' '10.99.1.2' '10.99.1.3' '10.99.1.4');

for i in ${ip_list[@]} ; do
    ssh -i ~/Downloads/abc.pem -t -t ec2-user@$i "sudo   python /home/user/abc.py"
done
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.