Lego
Lego

Reputation: 191

Sending output of 2 rsync commands in a bash script

I'm using an existing bash script and want to send the output of 2 rsync commmands so that it is passed to a variable which will then be used later, See below,

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)
ecode=$?
newfil=$(echo $rfiles | grep -c "Number of files transferred: 0")

However, I only get the output of the 1st rsync sent to my mail. How do include the output of the 2nd rsync command as well along with the first?

Thank you.

Upvotes: 1

Views: 806

Answers (2)

Samveen
Samveen

Reputation: 3540

The problem is with how your assignment is written. It's breaking up your line:

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

into rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/) && $(rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

Thus you get the output of just the first command in the variable. You'll need to change the command to

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/ && rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

To illustrate with another example:

samveen@precise:~$ a=$(echo 10) && $(echo 20)
-bash: 20: command not found
samveen@precise:~$ echo $a
10

Upvotes: 1

rectummelancolique
rectummelancolique

Reputation: 2237

You may want to put both commands inside the command expansion:

rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/ && rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

Upvotes: 0

Related Questions