1

I am trying to loop through a file to run commands remotely via SSH but its only sending the first command and stopping.

while read a b c; do ssh root@$remoteserverip "/usr/bin/mysql -e \"grant all privileges on $a.* to $b@'localhost' identified by '$c';\""  ; done < /dbusers.txt

MySQL logging shows:

Connect   root@localhost as anonymous on
Query     select @@version_comment limit 1
Query     grant all privileges on db1.* to dbu1@'localhost' identified by 'passwd'
Quit

and that's it.

Example contents of /dbusers.txt

db1 dbu1 passwd
db2 dbu2 passwd
db3 dbu3 passwd

If I use echo in front of ssh then it prints out all lines.

JCats
  • 127

0 Answers0