check an nfs mount in a script

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi,
Ive been looking for a way to do this but cant figure it out.

I have a script that checks an nfs mount with this condition (linux
bash) and makes sure its not full:

dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
if [ -n "$dirpresent" ]; then
etc etc
fi

My problem is if the nfs server is down, then the df command hangs so
the whole script hangs. Is there a way I can time the reponse so if
say I dont get a response after 5 seconds, then abort the df check?

Thanks
0
Reply cconnell_1 7/3/2008 10:04:40 PM

See related articles to this posting


On Thu, 03 Jul 2008 19:04:40 -0300, <cconnell_1@lycos.com> wrote:

> Hi,
> Ive been looking for a way to do this but cant figure it out.
>
> I have a script that checks an nfs mount with this condition (linux
> bash) and makes sure its not full:
>
> dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
> if [ -n "$dirpresent" ]; then
> etc etc
> fi
>
> My problem is if the nfs server is down, then the df command hangs so
> the whole script hangs. Is there a way I can time the reponse so if
> say I dont get a response after 5 seconds, then abort the df check?
>
> Thanks
> 


Try this:

read -t5 dirpresent < <(df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%")
0
Reply mop2 7/3/2008 11:29:09 PM

On 4 Jul, 00:29, mop2 <inva...@mail.address> wrote:
> On Thu, 03 Jul 2008 19:04:40 -0300, <cconnel...@lycos.com> wrote:
> > Hi,
> > Ive been looking for a way to do this but cant figure it out.
>
> > I have a script that checks an nfs mount with this condition (linux
> > bash) and makes sure its not full:
>
> > dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
> > if [ -n "$dirpresent" ]; then
> > etc etc
> > fi
>
> > My problem is if the nfs server is down, then the df command hangs so
> > the whole script hangs. Is there a way I can time the reponse so if
> > say I dont get a response after 5 seconds, then abort the df check?
>
> > Thanks
>
> Try this:
>
> read -t5 dirpresent < <(df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%")- Hide quoted text -
>
> - Show quoted text -


thanks this worked well. one side effect is after the script it leaves
the df -t commands around and also the script says its running from
ps.
is there any way to terminate the df or send a control-c to it after
the timeout?

0
Reply cconnell_1 7/4/2008 12:30:50 AM

On Thu, 03 Jul 2008 21:30:50 -0300, <cconnell_1@lycos.com> wrote:

> On 4 Jul, 00:29, mop2 <inva...@mail.address> wrote:
>> On Thu, 03 Jul 2008 19:04:40 -0300, <cconnel...@lycos.com> wrote:
>> > Hi,
>> > Ive been looking for a way to do this but cant figure it out.
>>
>> > I have a script that checks an nfs mount with this condition (linux
>> > bash) and makes sure its not full:
>>
>> > dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
>> > if [ -n "$dirpresent" ]; then
>> > etc etc
>> > fi
>>
>> > My problem is if the nfs server is down, then the df command hangs so
>> > the whole script hangs. Is there a way I can time the reponse so if
>> > say I dont get a response after 5 seconds, then abort the df check?
>>
>> > Thanks
>>
>> Try this:
>>
>> read -t5 dirpresent < <(df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%")- Hide quoted text -
>>
>> - Show quoted text -
>
>
> thanks this worked well. one side effect is after the script it leaves
> the df -t commands around and also the script says its running from
> ps.
> is there any way to terminate the df or send a control-c to it after
> the timeout?
>
> 


If the df survived, this may be a better solution:

if mount|grep -q ' nfs ' && df -T | grep -w nfs | grep -w $nfsdir | grep -q -wv "100%";then
etc etc
0
Reply mop2 7/4/2008 12:50:01 AM

On Thu, 03 Jul 2008 17:30:50 -0700, cconnell_1 wrote:

> On 4 Jul, 00:29, mop2 <inva...@mail.address> wrote:
>> On Thu, 03 Jul 2008 19:04:40 -0300, <cconnel...@lycos.com> wrote:
>> > Hi,
>> > Ive been looking for a way to do this but cant figure it out.
>>
>> > I have a script that checks an nfs mount with this condition (linux
>> > bash) and makes sure its not full:
>>
>> > dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
>> > if [ -n "$dirpresent" ]; then
>> > etc etc
>> > fi
>>
>> > My problem is if the nfs server is down, then the df command hangs so
>> > the whole script hangs. Is there a way I can time the reponse so if
>> > say I dont get a response after 5 seconds, then abort the df check?
>>
>> > Thanks
>>
>> Try this:
>>
>> read -t5 dirpresent < <(df -T | grep -w nfs | grep -w $nfsdir | grep
>> -wv "100%")- Hide quoted text -
>>
>> - Show quoted text -
> 
> 
> thanks this worked well. one side effect is after the script it leaves
> the df -t commands around and also the script says its running from ps.
> is there any way to terminate the df or send a control-c to it after the
> timeout?

Another way of doing this is with http://stromberg.dnsalias.org/~strombrg/
maxtime.html  It's specifically written with NFS mounts in mind.

However, on a hard,nointr mount, maxtime will leave processes behind too, 
though they should die as soon as the mount comes back.

To get around that, you'll probably need to change the mount options on 
your NFS mount - probably in /etc/fstab, /etc/vfstab, /etc/checklist, or 
an automount map.  You could probably change it to soft (mount will time 
out and disappear after a while) or intr (processes attempting to use the 
mount are interruptible even if the NFS mount is timing out).

0
Reply Dan 7/4/2008 12:53:15 AM

cconnell_1@lycos.com writes:

> dirpresent=`df -T | grep -w nfs | grep -w $nfsdir | grep -wv "100%"`
> if [ -n "$dirpresent" ]; then
> etc etc
> fi
>
> My problem is if the nfs server is down, then the df command hangs so
> the whole script hangs. Is there a way I can time the reponse so if
> say I dont get a response after 5 seconds, then abort the df check?


Decades ago when I had to deal with this (we had 100's of NFS file
servers), I seem to recall it was better to launch a job in the
background, if an NFS job might hang it up.

So it might be better to have a loop run the "df" command in the
background, and in another shell check the output. 

I did two other things to reduce the risk of server hanging:
  1) Keeping excess directories out of my searchpath

  2) creating a directory on the local machine that had symbolic links
  to the executables on remote diorectories, and use this directory in
  my searchpath instead of the other).

0
Reply Maxwell 7/5/2008 11:45:04 AM
comp.unix.shell 15039 articles. 25 followers. Post

5 Replies
783 Views

Similar Articles

[PageSpeed] 15


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

NFS Mount Checking
I have a snippet of a script that checks to make sure and NFS mount in mounted.......... If not it mounts it........ If it is it does nothing and goes on to the next part of the script..... The problem is the if then else..... It always executes the even if the NFS mount is mounted.... #!/bin/sh ......snip............ NFS="`df -k /mnt |tail -1 | cut -f1 -d :`" NFSSERVER="node1" # We must mount the share if [ $NFSSERVER != NFS ]; then echo "NFS mount is not yet mounted! Will mount!" >> $LOGFILE 2>&1 echo " " >> $LOGFILE 2>...

How to check if dir is NFS mounted?
Hi, What would be the best way to check from a C program whether a certain directory is on a NFS mounted filesystem or on a local filesystem? (using Debian GNU/Linux, if it matters) Thanks in advance. Regards, Heiko On Wed, 27 Apr 2005, it was written: > What would be the best way to check from a C program whether a certain > directory is on a NFS mounted filesystem or on a local filesystem? > (using Debian GNU/Linux, if it matters) Assuming that Linux supports it, the statvfs function is probably what you're after (see the f_basetype member). (I describe this in more de...

startup scripts that launch a program over NFS mounts
Hi, I need to create a startup script that will persistently try to launch an application that is located on a NFS mount until the application is actually started. The reason for doing so is because we have shared software & licenses on our NFS server that is not accessible after a power outage so licenses are not started because the NFS share is not present when the machine comes up. I can copy each file/application over to the local machine but this is a pain to administer d_dave@my-deja.com wrote: > Hi, > > I need to create a startup script that will persistently try to l...

Running a shell script in an NFS-mounted directory
I have my home directory on a machine A NFS-mounted at a some mount point in my home directory on a machine B. I have the same username and user ID in both machines; that is, for all practical purposes the remote home directory looks just like a subdirectory in B. Well, not quit. If I try to run a shell script (call it S) that lives in my home directory in A, while I am logged in at B, I get the following error: -bash: ./S: /bin/sh: bad interpreter: Permission denied Why? Running S from A itself works fine, and it does not contain or invoke anything not available under B. At 2007-...

Article
Followup-to is set to comp.os.linux.misc but can of course be ignored and over-ridden if you do not subscribe there. http://blog.eracc.com/2008/04/20/managing-pesky-nfs-mounts-with-a-shell-script/ Gene (e-mail: gene \a\t eracc \d\o\t com) -- Mandriva Linux release 2007.1 (Official) for i586 Got Rute? http://www.anrdoezrs.net/email-2546588-42121?isbn=0130333514 ERA Computers & Consulting - http://www.eracc.com/ Preloaded PCs - eComStation, Linux, FreeBSD, OpenServer & UnixWare ...

why can't a web browser mount a server nfs style and then web interactions can be scripted from there as files?
?? On Jul 8, 5:24=A0am, gavino <gavcom...@gmail.com> wrote: > ?? In order to do so, you probably must start by transforming Farenheit degrees into radian. On Jul 7, 11:24=A0pm, gavino <gavcom...@gmail.com> wrote: > ?? Syntax error. On Jul 8, 4:24=A0am, gavino <gavcom...@gmail.com> wrote (in the title): > why can't a web browser mount a server nfs style and then web > interactions can be scripted from there as files? Because there are a number of file operations that don't map to basic HTTP operations. The WebDAV extension to HTTP _is_ mountable; your...

NFS-mounting a mount-point
If I NFS-mount a directory A (on host X) to a mount point B (on host Y), can I then NFS-mount directory B to a mount point C (on Host Z)? Host X Host Y Host Z Dir A Mount Point B Mount Point C The reason I ask is because Host Z does not have access to Host X. "barcaroller" <barcaroller@music.net> writes: >If I NFS-mount a directory A (on host X) to a mount point B (on host Y), can >I then NFS-mount directory B to a mount point C (on Host Z)? > Host X Host Y Host Z > Dir A Mount Point B...

NFS mount won't mount at boot, but mount -a works fine.
I'm trying to get an NFS share to mount at boot time, but it won't. However, mount -a works just fine. I've tried playing with the retry= option with no luck. nsswitch.conf is hosts: files dns, and I have an entry for the host in /etc/hosts. The client machine is SUSE 8 (2.4 kernel), the server is SUSE 9 (2.6 kernel). My fstab entry looks like this: storage01:/array/ /home/array nfs rw,auto,sync Does anyone have any ideas on this? Thanks, Brian On Thu, 23 Sep 2004 18:03:55 +0000, BT wrote: > I'm trying to get an NFS share to mount at boot time, but it won&#...

NFS mounting issue. (can mount other servers, but can't mount one of them)
as title. First, that nfs server is fine, other client can mount, and only one client (A) can't. If I try to go into the mount point, it just stuck there and there is no output, even an error. So I have to do ctrl+c to stop it, and I got "bad directory" messages. Here is whole picture. Client A --- Can't mount NFS server B, but A can mount other servers like, C, D. NFS server B can be mounted by other client, like E, F.... I have checked everything, but couldn't find out. It was fine in the morning, and in the afternoon, it happend. And it acutally happened ...

NFS: mount an already mounted disk
Hi all, I have 3 computers say A,B and C A is windows, B is a linux box and C is a Solaris. B mount a disk from B with Samba since samba is not supported for mount under solaris I thought to export the disk from B and mount it on C via NFS. (hope it is clear....) What I get is "permission denied". All the configuration are ok because when trying with different directories it works fine. Any Idea? or workaround to solve the problem? thanks Marco ...

mount() = mount -f NFS,bg
in my program, I want to use mount to mount NFS. the rigth command is #mount -f NFS,bg u8:/ /nfs/u8 in my program I write: mflag=0; fstyp=0; cc=mount("u8/","/nfs/u8",mflag, fstyp,NULL,0); this function does not work. what should be mflag? what should be fstyp? gdm gdm wrote: > in my program, I want to use mount to mount NFS. the rigth command is > #mount -f NFS,bg u8:/ /nfs/u8 > > in my program I write: > mflag=0; > fstyp=0; > cc=mount("u8/","/nfs/u8",mflag, fstyp,NULL,0); > > this function does not work. what shoul...

vfstab nfs mounts not mounted automatic
Hello, In my vfstab I have a couple of nfs mounts. But after a reboot they are not mounted automatic ? I have to do : mount -a and then they are there. OS : Solaris 10 Sparc -------------- # NFS s1.domain.com:/export/server - /usr/local/folder1/server nfs - yes - s1.domain.com:/export/content - /usr/local/folder2/content nfs - yes - s1.domain.com:/export/docs/vi - /usr/local/folder3/docs/vi nfs - yes - ------------- Why is this ? Is this a startup order problem with the nfs client ? This is really getting to be a problem, so I hope someone can give me a quick answer ..... Thank you for a...

De-checking check boxes with a script
I know how to check a checkbox with a script using set field. Now, I want to "de-check" a box based on the value of a global field. I've tried the Find/Replace command, but I'm not really sure why that isn't working. Any suggestions? Thanks David Averbach UC Berkeley The replace script step will only work if the field in which you are performing the replace is available for editing on the current layout. Try a writing a loop that uses set field to clear the contents of the check box instead.Go to record (first) Freeze window Loop Set field (my_check_box_fiel...

Multiple nfs mounts on same mount point ?
How is this possible ? Two nfs mounts on a same mount point ? # df -k /mnt Filesystem 1024-blocks Free %Used Iused %Iused Mounted on apple:/home/data/media-server/DB2 384827392 27588984 93% 369128 6% /mnt guava01-admin:/export/lpp_source/TSM 384827392 27588984 93% 369128 6% /mnt invincible wrote: > How is this possible ? > > Two nfs mounts on a same mount point ? > > # df -k /mnt > Filesystem 1024-blocks Free %Used Iused %Iused Mounted on > apple:/home/data/media-server/DB2 384827392 27588984 93% > 369128 6% /mnt &...

Soft mount VS hard mount (NFS)
Hi all, Does any body have any idea what are the advantages and drawbacks of using a soft mount as compared to hard mount ? I read some articles that say that soft mount may cause data incosistency. Can anyone give me an example of a case that would lead to data inconsistency ? Thanx for any help in advance ... "rahul dev agg" <rahul_dev_agg@yahoo.co.in> writes: >Hi all, > Does any body have any idea what are the advantages and >drawbacks of using a soft mount as compared to hard mount ? >I read some articles that say that soft mount may cause >data in...

NFS: mounting nfs filesystem on boot time
Hi! I would like to boot nfs fs on client machine during boot time. In /etc/vfstab I should put: wasp:/var/mail - /var/mail nfs - yes rw Now, what will happen if nfs server is not present and client machine is rebooted? I wouldn't want for boot process to stop because it cannot mount nfs fs. Thanks! Mario. On Fri, 18 Jul 2003 11:57:16 +0200, Mario Pranjic <keeper@fly.srk.fer.hr> wrote: >Hi! > >I would like to boot nfs fs on client machine during boot time. > >In /etc/vfstab I should put: > >wasp:/var/mail - /var/mail nfs - yes rw > > >Now, what ...

mount mount file system using nfs
I have 3 Kubuntu/Linux PCs running on my LAN. PC1 is my primary PC that I do most of my work on. It runs the 'feisty' release of kubuntu, which I believe is release 7.04. PC2 is on the network mostly so I can use the disk space for backups. It also runs the 'feisty' release. PC3 is a new PC on which I plan to do a special project. From PC3 I would like to mount files systems from PC1 so I have access to information on my primary PC. PC3 runs the 'gutsy' release of Kubuntu which is release 7.10. NFS is working fine when I mount the filesystem on PC2 on to PC1. However,...

Script to check file system space and run a script
I have a script that I'm working on to simply check the free space of a mount and then perform an action based on the results, (i.e. less that 25% left do this...). Here is the script so far: #!/bin/ksh used_space=0 mount_point=${1:-"/tmp"} threshold=${2:-10} used_space=`df -k $mount_point | grep % | awk {'print $5'} | sed 's/%//g'` print "Free Space available under \"$mount_point\" is `expr 100 - $used_space`%.\n" if [ $used_space -gt $threshold ] then print "Space Utilization on \"$mount_point\" has exceeded the threshh...

2 NFS mount points, pointing to the same NFS export?
I know it's possible to have 2 NFS mounts, on the same host, to point to the same NFS export. Like this: mount 192.168.0.1:/storagearray /directory1 mount 192.168.0.1:/storagearray /directory2 However, is this the proper way to do it? Does this use up a lot of resources? Would a better approach be to just NFS mount once, say, to /Directory1, and then use a symbolic link for /Directory2 (pointing to /Directory1)? If anyone can shed some light on the pros and cons of this topic, I would gretly appreciate it. Thanks, Brian BT wrote: > I know it's possible to have 2...

Maximum Mount points in fstab and maximum nfs mounts
Hello All: I am trying to find out what is the maximum (theoritical or practical) limit on number mount points that one have in /etc/fstab. Also, what about mount points in /etc/mnttab (for fsys's that I mount while the system is up i.e. not during boot up and have no fstab entries). Additionally, what is the limit for total nfs mounts? RTFM on fstab has not shown much. Somewhere I found that nfs mounts limit is 400!? Has anyone looked into this before? Thank you for your assistance everyone! ...

NFS mount of SCO NFS server problem.... Any ideas??
Hi, I have two Slackware 9.1 Linux boxes. One is stock Slackware 9.1 with the 2.4.22 kernel and the other is Slackware 9.1 with the 2.4.29 kernel... On the first one (2.4.22) I can successfully mount an NFS disk shared from a SCO OpenServer 5.4 machine and everything works as expected... On the second machine, if I mount the same NFS shared disk, I can see the files but _some_ of the files are unreadable... If you try, for instance, to vi or cat one of the 'unreadable' files it says there are 0 bytes... but you can ls -al the file and see that it is of a certain non-zero size.... O...

NFS : can't mount NFS from linux to sco
I have a working nfs share on a linux (RH 7) box that is mountable from another linux server (ie it works I can read and write) When I try to mount it from the Sco 5.04 box I get an error: mount: invalid fs type <NFS> Any Ideas Thanks Brian BrianT wrote: > I have a working nfs share on a linux (RH 7) box that is mountable from > another linux server (ie it works I can read and write) > > When I try to mount it from the Sco 5.04 box I get an error: > mount: invalid fs type <NFS> > > Any Ideas > > Thanks > Brian > > Assuming you have ei...

mounting NFS
I get a +1 minute pause when mounting a NFS partition. The partition is 30GB with 21GB used. The server is a Mandrake 10.1 install with kernel 2.6.8 and the client is a Mandrake 10.1 install with kernel 2.6.11 and the nics are 100 Mps. Once the partition is mounted everything is fine. Any ideas? -- clear skies, Joe http://users.erols.com/jringer3/astro1.htm On Tue, 22 Mar 2005 11:36:49 -0600, Joe R wrote: > I get a +1 minute pause when mounting a NFS partition. The partition is > 30GB with 21GB used. The server is a Mandrake 10.1 install with kernel > 2.6.8 and the client is a ...

NFS mounting
I never needed to use NFS under OpenVMS until now. So are these steps ok ? By the way. I suggest Hoffmann to put a step-by-sten in the OpenVMS FAQs. In my OpenVMS nfs server: $ tcpip add proxy ctmagent /nfs=(incoming,outgoing) /host=clientnfs /gid=10 /uid=40 $ tcpip create container dka300:[nfs]/host=clientnfs/owner=[nnn,nnn]/username=ctmagent $ tcpip map "/nfs" dka300: $ tcpip map "/mynfs" dka300:[nfs] $ tcpip add export "/mynfs" /host=clientnfs In my OpenVMS nfs client: $ tcpip mount dnfs98: /host=servernfs / path="/mynfs" Regards FC ...