On Thursday 24 April 2008, Bob McGowan wrote:
> Chris wrote:
> > Hello,
> >
> > I want to run a script to rsync local files to a NAS mounted to
> > /mnt/music. Sometimes the NAS is not running, and I want to prevent the
> > script from writing to the mount directory:  is there any easy way to
> > prevent this?
> >
> > Thanks,
> >
> > C
>
> if [ -f /mnt/music/somefile ]
> then
>    # run your script here.
> fi

hey, cool.  I wouldn't have expected anything like this!

>
> There are other ways to do the test, depending on how the mount was
> done:  at boot with fstab, mounted by a user using 'mount', automounted,
> or by some other method.
>
> If mounted at boot time but the mount fails, output of 'mount' with no
> args would not have /mnt/music in it, so grep could be used in that case.
>
> If mounted by the user, then mount would fail if the NAS were down, and
> that could be tested for (assuming the 'mount' is part of the script).
>
> Or, 'df /mnt/music', which returns info for the mounted device, if
> mounted, and for the root device if not.
>
> These latter suggestions require pipes to grep for values that are valid
> for the mounted condition, with checks on the grep exit status
> determining whether or not you continue.
>
> For example, with the 'df' suggestion:
>
> if df /mnt/music | grep /mnt/music > /dev/null
> then
>    # run your script here.
> fi

I'll give this a shot.

BTW I'm running rsyc -rltuDOvz which seems like the only way to get it to work 
to my NAS (mounted as smbfs in fstab) without all sorts of group and 
timestamp errors.  Ths thing is that the files are landing on the NAS with 
the copy date, not the date they have on the source, which I don't think i 
really like.

C

>
> Using I/O redirection, with grep, is more portable, but for Linux
> systems (or, specifically, any system with Gnu grep), you can use 'grep
> -q /mnt/music' instead.



-- 
C. Hurschler


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to