Sponsored Content
Top Forums Shell Programming and Scripting bash script to check if mounted, and mount if not Post 302293696 by unSpawn on Tuesday 3rd of March 2009 04:07:39 PM
Old 03-03-2009
Quote:
Originally Posted by graysky
1) Check to see if the mount is active
For this you could use 'grep'. But not for output, just the exit value (meaing "$?"). Check /proc/mounts. Mount a directory. Check /proc/mounts again. Try to grep the mounted partition line from /proc/mounts.


Quote:
Originally Posted by graysky
2) If it's not active, try to mount it
You know the mount command, right? So if the previous 'grep' fails you could use the exit value as cue to mount it. To test the mount bit you could use a command that always outputs exit value 1: 'false'. Test it with 'false || echo doSomething; false && echo doSomethingElse'. You'll see.


Quote:
Originally Posted by graysky
3) If it won't mount because the nfs server is down, wait 45 s then try again looping indefinitely until the nfs server is up
"Wait" here means 'sleep'. Try 'man sleep' to find out how to use it. Again you can use a "negative" (in shell) exit value.


Quote:
Originally Posted by graysky
4) Once the mount is active, run a program and exit
Same here: use the exit value.

Here's some Bash scripting guides that will help you glue those things together if you like: BASH Programming - Introduction HOW-TO, Bash Guide for Beginners,
Advanced Bash-Scripting Guide.

Once you have something to test out, posting it in code tags would make things easier in case things went awry somewhere.
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

how to assign same mount point for file systems mounted on physical disks

We have 6 hard disks attached to the hardware. Of this 2 hard disks are of 9 GB each. Now I want combine both the same in such a way that i see a combined entry in the output of df -k . The steps I follow are 1. Create partition on hard disks (Using format partition) 2. Run newfs -v for... (6 Replies)
Discussion started by: Hitesh Shah
6 Replies

2. SCO

/ partition is mounted but not present in mount

Hello , I 've got a problem with the root partition on my SCO 5.0.5 . When I check the disk with df or mount , I can 't see the root filesystem . # mount /stand on /dev/boot read only on Tue Sep 05 16:13:51 2006 /home on /dev/home read/write on Tue Sep 05 16:14:41 2006 But , if I try... (3 Replies)
Discussion started by: npn35
3 Replies

3. Solaris

Remote mount an already mounted nfs filesystem

Hello all, We're using JET to build our systems.. I'm in the process of needing to build a centrally located JET box with access to all our networks rather that 2 or 3 dotted around. Part of the means I need to locate the boot & OS images on an NFS mount (via NETAPP filer).. However in the... (1 Reply)
Discussion started by: itsupplies
1 Replies

4. UNIX for Dummies Questions & Answers

mount points are already mounted

Hi, I have some issue with the mounting/unmounting on my sun solaris box. Actually their is one script that mount the file system take the backup of databases and unmount the file system.Last week this script failed to mount the file system with the below error message: + echo fs_check.sh:... (1 Reply)
Discussion started by: biju.mp
1 Replies

5. Shell Programming and Scripting

bash script to get all mounted devices

Hi, to all I'm writing script with zenity to benchmark selected disk with tools like; hdparm, seeker (to found in here > How fast is your disk? | LinuxInsight) With this piece of code i try to get all mounted devices to variables to use it with selection menu, but i stuck and don't know how... (5 Replies)
Discussion started by: m0z4rt
5 Replies

6. Shell Programming and Scripting

Shell script for Server Mount Point space check

Does anybody have anything I can use to help me out with this one? (4 Replies)
Discussion started by: lbone007
4 Replies

7. Shell Programming and Scripting

How to check if a partition is mounted or not with bash?

How to check if a partition is mounted or not with bash? And when is $? variable one? Please give example. (10 Replies)
Discussion started by: cola
10 Replies

8. Shell Programming and Scripting

Bash script problem to mount

#!/bin/bash userid=$(id -u) options="rw,exec,users,uid="${userid}",gid="${userid}"" while ;do echo -n "Enter device you want to mount (Example: /dev/sda11): " read device echo "Selected device: ${device}" if ;then echo -n "Enter... (3 Replies)
Discussion started by: cola
3 Replies

9. Solaris

In Solaries 10 how to mount multiple volume on same mounted point

Hi , I am completely stuck and not getting any clue to come out this . So looking for help Q : I have salaries 10 in server with that Dell Equallogic storage connected. in dell Equlalogic in i have 70 TB storage . I created 7 volumes 10 TB each . In Solaries 10 i have syslog server i... (1 Reply)
Discussion started by: Roahn Tiwari
1 Replies

10. Shell Programming and Scripting

Script to check if file systems are mounted

Hi I have the following piece of code, running on a solaris 10 O.S., that is not working for NFS file systems: for vol in `grep -E 'vxfs|ufs|nfs' /etc/vfstab | egrep -v '^#' | awk '{ print $3 }'` do if df -k $vol | grep $vol > /dev/null then outputOK "Filesystem: $vol mounted" else... (1 Reply)
Discussion started by: fretagi
1 Replies
MKILL(8)						       The SuSE boot concept							  MKILL(8)

MKILL
Mkill - Send processes making a active mount point busy a signal SYNOPSIS
mkill [-SIG] [-u] /mnt1 [/mnt2...] mkill [-l] DESCRIPTION
mkill determines all active mount points from /proc/mounts and compares this with the specified mount points. Then mkill seeks for pro- cesses making this mount points busy. For this search only the links found in /proc/<pid>/ are used to avoid hangs on files provided by network file systems like nfs(5). The default signal is SIGTERM for termination. If a mount point is not active, that is that it is not found in /proc/mounts, mkill will do exactly nothing. OPTIONS
-<SIG> Signals can be specified either by name (e.g. -HUP, -SIGHUP) or by number (e.g. -1). -0 The special signal 0 force mkill to list all processes making the specified mount point busy. -u Perform a lazy umount on the specified mount points before sending the signal SIGTERM or SIGKILL. -l List all known signals. EXAMPLES
mkill -TERM /var This will terminate all processes accessing a seperate /var partition. mkill -HUP /dev/pts All processes using a pseudo-terminal slave will hangup. RETURN VALUE
Always success which is that zero is returned. SEE ALSO
fuser(1), proc(5), umount(8). COPYRIGHT
2008 Werner Fink, 2008 SUSE LINUX Products GmbH, Germany. AUTHOR
Werner Fink <werner@suse.de> 3rd Berkeley Distribution Jan 31, 2008 MKILL(8)
All times are GMT -4. The time now is 06:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy