Suppose 3 hosts called host1 ,host2, host3 I want to replace the string 5801 on file /etc/FAKEFILE using +1 for every host,with sed(but perl,awk also ok) using ssh. Must return 5802 on host1 5803 on host2 5804 on host3 Thanks
-
Are the hostnames somehow included in the file, or do you want to change a string depending on actual machine hostname separately for each machine?– techrafSep 30, 2015 at 17:38
-
Depending on machine number,on host1 5802+1 return 5803,on host2 5802+2 return 5804,and so on– elbarnaSep 30, 2015 at 17:42
Add a comment
|
1 Answer
#!/bin/bash
N1=5801
N2=5801
for i in 1 2 3
do
N2=$((N2 + 1))
CMD="sed -i 's/${N1}/${N2}/' /tmp/file"
echo "running $CMD on host$i..."
ssh user@host$i "$CMD"
done