1

If a script for use another script for rsync backups, type Time Machine.

But when finish first user program stop

backup.sh

#!/bin/bash                                                                                                                                                                                                                                                                                       
while read A; do
    echo $A
    ssh [email protected] "[[ -d /Volumes/MACBACKUP/desarrollo_backups/$A ]] || mkdir /Volumes/MACBACKUP/desarrollo_backups/$A; touch /Volumes/MACBACKUP/desarrollo_backups/$A/backup.marker"
    bash /home/vagrant/rsync_tmbackup.sh $A/ [email protected]:/Volumes/MACBACKUP/desarrollo_backups/$A/
done < cuentas.txt

File cuentas.txt

account1
account2
..
accountN

When run backup.sh

account1  # comment first iteration on while
rsync_tmbackup: Previous backup found - doing incremental backup from [email protected]:/Volumes/MACBACKUP/desarrollo_backups/account1/2016-11-03-075246
rsync_tmbackup: Creating destination [email protected]:/Volumes/MACBACKUP/desarrollo_backups/account1/2016-11-03-080415
rsync_tmbackup: Starting backup...
rsync_tmbackup: From: castris
rsync_tmbackup: To:   [email protected]:/Volumes/MACBACKUP/desarrollo_backups/account1/2016-11-03-080415
rsync_tmbackup: Running command:
rsync_tmbackup: rsync  -e 'ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -D --compress --numeric-ids --links --hard-links --one-file-system --itemize-changes --times --recursive --perms --owner --group --log-file '/home/vagrant/.rsync_tmbackup/2016-11-03-080416.log' --link-dest='/Volumes/MACBACKUP/desarrollo_backups/account1/2016-11-03-075246' -- 'castris/' '[email protected]:/Volumes/MACBACKUP/desarrollo_backups/account1/2016-11-03-080415/' | grep -E '^deleting|[^/]$'
Warning: Permanently added '192.168.1.33' (ECDSA) to the list of known hosts.
rsync_tmbackup: Backup completed without errors. # Here finish first iteration on while, and muts be with second iteration, but bash end while

And stop, instead made backup for next user account2

2 Answers 2

1

could you use "ssh -n" as below;

#!/bin/bash                                                                                                                                                                                                                                                                                       
while read A; do
echo $A
ssh -n [email protected] "[[ -d /Volumes/MACBACKUP/desarrollo_backups/$A ]] || mkdir /Volumes/MACBACKUP/desarrollo_backups/$A; touch /Volumes/MACBACKUP/desarrollo_backups/$A/backup.marker" 
bash /home/vagrant/rsync_tmbackup.sh $A/ [email protected]:/Volumes/MACBACKUP/desarrollo_backups/$A/
done < cuentas.txt

man ssh ;

-n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background. A common trick is to use this to run X11 programs on a remote machine. For example, ssh -n shadows.cs.hut.fi emacs & will start an emacs on shadows.cs.hut.fi, and the X11 connection will be automatically forwarded over an encrypted channel. The ssh program will be put in the background. (This does not work if ssh needs to ask for a password or passphrase; see also the -f option.)

Sign up to request clarification or add additional context in comments.

4 Comments

ssh -n not resolve. Problem is "after" run bash program rsync_tmbackup.sh, not after run ssh command. Thanks.
@abkrim, you also use ssh command in rsync_tmbackup.sh. could you also change this in your script; rsync -e 'ssh -n -p ...
Why? I don't like run a ssh command. My question it's other. Question it's a about fail bash script after run first iteration on while. ssh it's a line of program. bash ... it's OTHER line on bash script.
@abkrim; ssh command consumes all your remaining lines, so only run first loop.
0

I'm pretty sure @MustafaDOGRU is right about the basic problem: when the loop starts, read reads the first line of cuentas.txt (as expected), but then something in the middle of the loop reads the rest of the file so when the script tries to read the next line... there's nothing left, and so it figures it's done and exits. Mustafa's approach was to try to figure out what part of the middle of the loop was reading and get it to stop, but it looks like there are multiple things doing it, and tracking them down may be annoying. But there's another way: pass the file's contents over something other than the standard input:

#!/bin/bash                                                                                                                                                                                                                                                                                       
while read -u3 A; do
    echo $A
    ssh [email protected] "[[ -d /Volumes/MACBACKUP/desarrollo_backups/$A ]] || mkdir /Volumes/MACBACKUP/desarrollo_backups/$A; touch /Volumes/MACBACKUP/desarrollo_backups/$A/backup.marker"
    bash /home/vagrant/rsync_tmbackup.sh $A/ [email protected]:/Volumes/MACBACKUP/desarrollo_backups/$A/
done 3< cuentas.txt

The 3< cuentas.txt directs cuentas.txt to file descriptor #3 rather than standard input (which is fd #0), and the read -u3 reads from fd #3, so those should work properly together. Since fd #3 is normally unused, the chance of anything in the middle of the loop messing with it is pretty small.

2 Comments

Ok. All roght. I put a other script. This script same process, but not run bash /home/vagrant/rsync_tmbackup.sh. Result? Of course, run all iterations without any problem. I've a lot of scripts with loops, for running several process o remote machines, and this it's first time with this issue. paste.tamainut.info/view/e6766181 This code, execute remote command, create remote dirs, and after
@abkrim I'm not sure I'm understanding you correctly, but if some scripts work without needing the fd 3 trick, it's because nothing inside the loop reads from standard input. In general, while read A; do ... done <file might work depending on what's inside the loop; but while read -u3 A; do ... done 3<file will work, for almost any loop contents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.