1

I am a newbie to bash scripting. I am trying to copy a gz file, then change permissions and untar it on remote servers (all centos machines).

#!/bin/bash

pwd=/home/sujatha/downloads
cd $pwd
logfile=$pwd/log/`echo $0|cut -f1 -d'.'`.log
rm    $logfile
touch $logfile



server="10.1.0.22"

for a in $server
do
scp /home/user/downloads/prometheus-2.0.0.linux-amd64.tar.gz 
ssh -f sujatha@10.1.0.22 "tar -xvzf/home/sujatha/downloads/titantest/prometheus-2.0.0.linux-amd64.tar.gz"
        sleep   2
        echo
done
exit

The scp part is successfull. But not able to do the remaining actions. after untarring I also want to add more actions like appending a variable to the config files. all through the script. Any advise would be helpful

Pavel
  • 6,878
  • 2
  • 26
  • 41
user9062792
  • 11
  • 1
  • 5
  • 1
    What if instead of attempting to run multiple individual commands, you run a script on the remote machine? Also, [this post](https://stackoverflow.com/questions/4412238/what-is-the-cleanest-way-to-ssh-and-run-multiple-commands-in-bash) may help you out too. – burnttoast11 Dec 18 '17 at 20:32
  • 2
    Are you sure that the scp part is successful? I see only one argument. – Benjamin W. Dec 18 '17 at 21:31

1 Answers1

1

Run a bash session in your ssh connection:

ssh 192.168.2.9 bash -c "ls; sleep 2; echo \"bye\""
Veda
  • 1,714
  • 1
  • 15
  • 29