Multiple Remote Mounts in a script

I am having a problem figuring out how to include 2 remote mounts in a script included in the Rclone application for QNAP NAS.

Basically I have setup 2 remotes: gdrive and gdrive2

I have a script called RClone.sh that work just fine with only one mount (gdrive) but I can´t figure out how to incorporate a second mount (gdrive2) in the same script. This is how the RClone.sh script looks like:

#!/bin/sh
CONF=/etc/config/qpkg.conf
QPKG_NAME="RClone"
QPKG_ROOT=/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}
APACHE_ROOT=/share//sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info

export QPKG_NAME QPKG_ROOT APACHE_ROOT

export SHELL=/bin/sh
export LC_ALL=en_US.UTF-8
export USER=admin
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export TZ=$(/sbin/getcfg System 'Time Zone' -f /etc/config/uLinux.conf)
export TERM=xterm
export HOSTNAME
export QPKG_ROOT QPKG_NAME
export PATH=$QPKG_ROOT:$PATH
export HOME=$QPKG_ROOT

export PIDF=/var/run/rclone.pid

case "$1" in
start)
ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
if [ "$ENABLED" != "TRUE" ]; then
echo "$QPKG_NAME is disabled."
exit 1
fi

/bin/ln -sf $QPKG_ROOT /opt/$QPKG_NAME
/bin/ln -sf $QPKG_ROOT/rclone /usr/bin/rclone
cd $QPKG_ROOT
/usr/bin/rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 &
echo $! > $PIDF

;;

stop)

ID=$(more /var/run/rclone.pid)

    if [ -e $PIDF ]; then
        kill -9 $ID
        rm -f $PIDF
    fi

killall -9 rclone

rm -rf /opt/$QPKG_NAME
rm -rf /usr/bin/rclone

;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

How can I include the second mount (gdrive2) into that script? I have tried different ways but it won´t work. Any suggestions please?? Thanks!!!!

Sup bro :wink:

This part is your rclone mount command ^
Notice that it ends with a &
This signifies that this command should be run in the background (ie. the script does not stop and wait for it to finish, which is good because mounts don't "finish" running until they stop and dismount)

Therefore, if you want to add a second (or third, or fourth) mount it should be as simple as copy-pastnig that entire line and putting it below the original one (including the & at the end)

And then of course modify the command as you please, because presumably you don't just want 2 identical ones (and that would error anyway if they tried to mount to the same folder). The script should then just execute both of them in sequence.

What are you trying to mount this time?

Just to clarify, here is an example:

/usr/bin/rclone mount **gdrive2**: /share/CACHEDEV1_DATA/**gdrive2** --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 &
/usr/bin/rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 &

You should replace that with "--daemon" rather than making it a background process.

Yea, probably that would be more ideal.

I am honestly just worried about breaking anything here. We spent like at least a day trying to wrangle this into working on a QNAP system that would just refuse to cooperate (very much a non-standard Linux system, so something I had even less experience with). The OP has very little Linux experience, so it was a bit of an ordeal :stuck_out_tongue:

@ColorDrome Please make a backup of your existing script (like I showed you) before making any big changes you are not confident about. Just don't break it lol.

Hey man! Nice to see you again. I left you a message in Skype. I thought you were busy :slight_smile:

Let me try again to change that script. I think I have done it as you said it but for some reason it wouldn´t work. Maybe I have done something wrong. I will double check. Thanks!

No no don´t worry about it :slight_smile: I did already :slight_smile:

I haven't been so well for some weeks now. Apologies for missing your message. I am not as attentive as I should be when I am like this.

No worries Stigma, I totally understand. I hope you´ll feel better. Thanks for getting back to me!

thanks Animosity! so instead of putting the "&" I will replace it with --daemon ? correct?

Just looking at the code and there is already a similar flag: --daemon 2>&1 >

Is this another type of daemon flag?

That is the same flag yes. I think you got that part from the other guy who helped you.
The extra stuff at the end I believe says "output standard-output and error-output to the logfile, so that is fine. It's just an alternative way of creating a log-file instead of using the rclone built-in --log-file flag.

That redirection part should be at the end of the line though, so you should probably move the --umask 002 to before --daemon, or else I don't think that last flag will take effect.

ie:
--log-level INFO --umask 002 --daemon 2>&1 > /var/log/gdrive-mount.log &

Because we are already using --daemon here (which specifies to run this as a background deamon) it's probably not required to have the & here at all. However - it should do no harm, just be superflous, so I would just leave it honestly.

Unless @Animosity022 says otherwise that is. He is much more experienced with bash than I am.

this is the script right now:

#!/bin/sh
CONF=/etc/config/qpkg.conf
QPKG_NAME="RClone"
QPKG_ROOT=/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}
APACHE_ROOT=/share//sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info

export QPKG_NAME QPKG_ROOT APACHE_ROOT

export SHELL=/bin/sh
export LC_ALL=en_US.UTF-8
export USER=admin
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export TZ=$(/sbin/getcfg System 'Time Zone' -f /etc/config/uLinux.conf)
export TERM=xterm
export HOSTNAME
export QPKG_ROOT QPKG_NAME
export PATH=$QPKG_ROOT:$PATH
export HOME=$QPKG_ROOT

export PIDF=/var/run/rclone.pid

case "$1" in
start)
ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
if [ "$ENABLED" != "TRUE" ]; then
echo "$QPKG_NAME is disabled."
exit 1
fi

/bin/ln -sf $QPKG_ROOT /opt/$QPKG_NAME
/bin/ln -sf $QPKG_ROOT/rclone /usr/bin/rclone
cd $QPKG_ROOT
/usr/bin/rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 --daemon

/usr/bin/rclone mount gdrive2: /share/CACHEDEV1_DATA/gdrive2 --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 --daemon
echo $! > $PIDF

;;

stop)

ID=$(more /var/run/rclone.pid)

    if [ -e $PIDF ]; then
        kill -9 $ID
        rm -f $PIDF
    fi

killall -9 rclone

rm -rf /opt/$QPKG_NAME
rm -rf /usr/bin/rclone

;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

Only the gdrive remote is mounting though. The gdrive2 is not mounting. Maybe I should have divided the two mounting lines better??

That isn't really how I suggested it.

as I said, I would do:

/usr/bin/rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --umask 002 --daemon 2>&1 > /var/log/gdrive-mount.log &

/usr/bin/rclone mount gdrive2: /share/CACHEDEV1_DATA/gdrive2 --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --umask 002 --daemon 2>&1 > /var/log/gdrive-mount.log &

But of course, let me be very clear that
gdrive2: /share/CACHEDEV1_DATA/gdrive2
was just some random example I made up on the spot.

  • There still needs to actualy exist a remote called gdrive2
  • There still needs to exist a folder named /share/CACHEDEV1_DATA/gdrive2

You have to actually make sure what matches whatever you configured in rclone. You haven't told me what you are mounting so I just gave a general example.

The gdrive2 is an actual directory I have created in the CACHEDEV1_DATA directory. I have also updated the config file with the gdrive2 remote as well.

Basically I have setup a remote that connects to another folder in my Google Drive. The gdrive2 remote is a real remote, not just one created for example

Have you verified that gdrive2: also works ok?
by for example running rclone ls gdrive2:

Assuming you have this should work as-is then.
Try it with the changed lines I suggested.

Yes I have. As a matter of fact I was able to manually mount both remotes with no problem

Let me insert the lines you mentioned and see if it works....brb

still nothing, only one remote is mounting, gdrive but gdrive2 is not mounting :frowning:
Here is the script again:
#!/bin/sh
CONF=/etc/config/qpkg.conf
QPKG_NAME="RClone"
QPKG_ROOT=/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}
APACHE_ROOT=/share//sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info

export QPKG_NAME QPKG_ROOT APACHE_ROOT

export SHELL=/bin/sh
export LC_ALL=en_US.UTF-8
export USER=admin
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export TZ=$(/sbin/getcfg System 'Time Zone' -f /etc/config/uLinux.conf)
export TERM=xterm
export HOSTNAME
export QPKG_ROOT QPKG_NAME
export PATH=$QPKG_ROOT:$PATH
export HOME=$QPKG_ROOT

export PIDF=/var/run/rclone.pid

case "$1" in
start)
ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
if [ "$ENABLED" != "TRUE" ]; then
echo "$QPKG_NAME is disabled."
exit 1
fi

/bin/ln -sf $QPKG_ROOT /opt/$QPKG_NAME
/bin/ln -sf $QPKG_ROOT/rclone /usr/bin/rclone
cd $QPKG_ROOT
/usr/bin/rclone mount gdrive: /share/CACHEDEV1_DATA/gdrive --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 &

/usr/bin/rclone mount gdrive2: /share/CACHEDEV1_DATA/gdrive2 --config=/etc/config/rclone.conf --rc --rc-web-gui-update --rc-addr localhost:5572 --rc-user qnap --rc-pass qnap --allow-other --allow-non-empty --tpslimit 10 --tpslimit-burst 10 --buffer-size 32M --cache-chunk-size=10M --use-mmap --cache-info-age=168h --cache-workers=5 --cache-dir /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-upload-path /share/CACHEDEV1_DATA/Others/rclone/ --cache-tmp-wait-time 60m --log-level INFO --daemon 2>&1 > /var/log/gdrive-mount.log --umask 002 &
echo $! > $PIDF

;;

stop)

ID=$(more /var/run/rclone.pid)

    if [ -e $PIDF ]; then
        kill -9 $ID
        rm -f $PIDF
    fi

killall -9 rclone

rm -rf /opt/$QPKG_NAME
rm -rf /usr/bin/rclone

;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

--rc-addr localhost:5572

You can't run both on the same port - or the second instance will error and exit.
Change the second one to for example 5573

There is no need to paste the entire script each time. I didn't make the rest of this as you know, so I have no intention of modifying anything besides the rclone stuff we added.