prevent writing to unmounted directory
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 How are you accessing the NAS? NFS? SAMBA? -- Damon L. Chesser damon@damtek.com http://www.linkedin.com/in/dchesser -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
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 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 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. -- Bob McGowan |
prevent writing to unmounted directory
On Thursday 24 April 2008, Damon L. Chesser 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 > > How are you accessing the NAS? NFS? SAMBA? smbfs > > -- > Damon L. Chesser > damon@damtek.com > http://www.linkedin.com/in/dchesser -- C. Hurschler -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
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 debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
Touch a file on the NAS share with a name such as
NAS.HERE, and in your script check that that file exists. If it exists, then it's mounted, if not, then it's not mounted. Ken --- Chris <list.hurschler@gmx.de> wrote: > On Thursday 24 April 2008, Damon L. Chesser 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 > > > > How are you accessing the NAS? NFS? SAMBA? > > smbfs > > > > > -- > > Damon L. Chesser > > damon@damtek.com > > http://www.linkedin.com/in/dchesser > > > > -- > C. Hurschler > > > -- > To UNSUBSCRIBE, email to > debian-user-REQUEST@lists.debian.org > with a subject of "unsubscribe". Trouble? Contact > listmaster@lists.debian.org > > __________________________________________________ _________ Yahoo! For Good. Give and get cool things for free, reduce waste and help our planet. Plus find hidden Yahoo! treasure http://green.yahoo.com/uk/earth-day/ -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
On Thu, Apr 24, 2008 at 10:18:48PM +0200, Chris wrote:
> 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! another alternative, since it's likely that the contents of /mnt/music could change (I know mine does), why not do this. umount /mnt/music touch /mnt/music/SENTINEL then do if [ -f /mnt/music/SENTINEL ] then echo "Music share is not mounted!" exit 1; fi #run your script here the only way SENTINEL will appear is when the NAS is *not* mounted. And this protects whatever you are using as your SENTINEL from inadvertent deletion. A |
prevent writing to unmounted directory
On Friday 25 April 2008, Andrew Sackville-West wrote:
> On Thu, Apr 24, 2008 at 10:18:48PM +0200, Chris wrote: > > 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! > > another alternative, since it's likely that the contents of /mnt/music > could change (I know mine does), why not do this. > > umount /mnt/music > touch /mnt/music/SENTINEL > > then do > > if [ -f /mnt/music/SENTINEL ] > then > echo "Music share is not mounted!" > exit 1; > fi > > #run your script here > > the only way SENTINEL will appear is when the NAS is *not* > mounted. And this protects whatever you are using as your SENTINEL > from inadvertent deletion. > > A that seems like a nice approach. Why do I need to touch the SENTINEL file? C -- C. Hurschler -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
On Thursday 24 Apr 2008, Chris wrote:
> mounted as smbfs in fstab I thought smbfs was unmaintained and that cifs was the better option - anyone? Chris. -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
Chris wrote:
that seems like a nice approach. Why do I need to touch the SENTINEL file? C Chris, in the example, you touch the file ONCE to make it exist. Then when you mount music, it will "mask" the file. That file will only show up when your smb mount for music is not mounted. Try it. When you make a file in a dir /tmp/test then mount something in /tmp/test the contents of /tmp/test will only show the mounted files. When you unmount /tmp/test the original file will still be there. I think this is a rather elegant approach independent of networking. If networking is down, you will see the "touched" file. If networking is up and smb/CIF is working, you will not see it. The "touched" file will not be overwritten by your file moving/deletion/backups/restores. Does that help? -- Damon L. Chesser damon@damtek.com http://www.linkedin.com/in/dchesser -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
prevent writing to unmounted directory
Andrew Sackville-West wrote:
On Thu, Apr 24, 2008 at 10:18:48PM +0200, Chris wrote: 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! another alternative, since it's likely that the contents of /mnt/music could change (I know mine does), why not do this. umount /mnt/music touch /mnt/music/SENTINEL then do if [ -f /mnt/music/SENTINEL ] then echo "Music share is not mounted!" exit 1; fi #run your script here the only way SENTINEL will appear is when the NAS is *not* mounted. And this protects whatever you are using as your SENTINEL from inadvertent deletion. A That's an excellent suggestion. Way cool! -- Bob McGowan |
| All times are GMT. The time now is 06:58 PM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.