script for continuous rsync of directory with prompting only once for a password
<p>Following situation:
We have a facility in a remote building in a different network. Various users are going to this facility and collect data, which have to be transferred to their home cluster node. We can transfer these data via ssh/rsync and I would like to transfer the data continuously as soon as new data is available (e.g. every 30 sec). I would like to have a continues transfer, because these the data (approx. 0.5 TB/h) should be transferred once the user goes home and a continues transfer would allow people to start processing data while it is collected.</p>

<p>For this purpose I would like to write an "rsyncdir" script, which prompts the user only once for a password, when he starts the script. In an ideal case the password would be stored in an internal variable and is used every time rsync is launched until the script is interrupted.</p>

<p><strong>Problems:</strong></p>

<ol>
<li><strong>ssh keys</strong> are no option, because there is only one common account on the local machine, which is used by everybody and every user of the script would have to bring his private key for his private remote account, which would have to be stored on the local machine. Besides a severe security issue (in case somebody forgets to delete the key) this is not a one-script-all-users solution.</li>
<li>setting the environment variable <strong>RSYNC_PASSWORD</strong> does not work with remote shells</li>
<li>--password-file does not work with remote shells</li>
<li>There is neither <strong>sshpass</strong> nor <strong>expect</strong> available</li>
<li>mounting the remote file system via <strong>sshfs</strong> + RSYNC_PASSWORD is no option.</li>
</ol>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>#!/bin/bash

read -p "Password: " -s password

while true ; do 

 rsync -avhPe ssh /localdir/ username@cluster.node.com:/psf/remotedir/
 sleep 30

done</code></pre>
</div>
</div>
</p>

<p>Is there a way to do that?</p>

<p>Thank you!</p>