bash - While loop executes only once when using rsync -



bash - While loop executes only once when using rsync -

i've created bash script migrate sites , databases 1 server another: algorithm:

parse .pgpass file create individual dumps specified postgres db's. upload said dumps server via rsync. upload bunch of folders related each db other server, via rsync.

since databases , folders have same name, script can predict location of folders if knows db name. problem i'm facing loop executing 1 time (only first line of .pgpass beingness completed).

this script, run in source server:

#!/bin/bash # read each line of input file, parse args separated semicolon (:) while ifs=: read host port db user pswd ; # create dump. no need come in password we're using .pgpass pg_dump -u $user -h $host -f "$db.sql" $db # create dir in destination server re-create files ssh user@destination.server mkdir -p webapps/$db/static/media # re-create dump destination server rsync -azhr $db.sql user@destination:/home/user # re-create website files , folders destination server rsync -azhr --exclude "*.thumbnails*" webapps/$db/static/media/ user@destination.server:/home/user/webapps/$db/static/media # @ point expect script go on next line, if exits @ first line done < $1

this .pgpass, file parse:

localhost:*:db_name1:db_user1:db_pass1 localhost:*:db_name3:db_user2:db_pass2 localhost:*:db_name3:db_user3:db_pass3 # many more...

and how i'm calling it:

./my_script.sh .pgpass

at point works. first dump created, , transferred destination server along related files , folders. problem script finishes there, , won't parse other lines of .pgpass. i've commented out lines related rsync (so script creates dumps), , works correctly, executing 1 time each line in script. how can script not exit after executing rsync?

btw, i'm using key based ssh auth connect servers, script prompt-less.

let's inquire shellcheck:

$ shellcheck yourscript in yourscript line 4: while ifs=: read host port db user pswd ; ^-- sc2095: ssh may swallow stdin, preventing loop working properly. in yourscript line 8: ssh user@destination.server mkdir -p webapps/$db/static/media ^-- sc2095: add together < /dev/null prevent ssh swallowing stdin.

and there go.

bash ssh rsync

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -