Solved

Need a script to check for a mount then mount share if not found

Posted on 2006-11-30
5
298 Views
Last Modified: 2013-12-27
I need a script to check if a share is mounted. Lets call the server ABC and the share 123. I need a script to see if the share is mounted and if it is then call another script. If it is not mounted then the script should check to see if /mnt has a share mounted to it. If not then mount the share to /mnt. If /mnt is already used then check /tmp and mount to /tmp. If both /mnt and /tmp are already being used then exit and do nothing. Once the share is mounted then call another script.
0
Comment
Question by:SpyderGST1
  • 3
  • 2
5 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 18052030
why reinwenting the wheel? use automounter

Anyway:
(cd /mnt/ABC/123 2>&1) && /path/to/another/script || (mount /mnt/ABC/123 && /path/to/another/script)

# assumes that you have setup /etc/fstab proper
0
 

Author Comment

by:SpyderGST1
ID: 18054428
Thanks you.
Because I need to put this on several servers across the US and I don't admin these servers. I need this mount for my app. I can suggest it to the Unix team.
Thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 18055871
ok, if you don't admin these servers someone need to configure them for your mounts
then my suggestion should work (well you may write a script of your choice using the proper if--then--else syntax, which willmake it more portable)
0
 

Author Comment

by:SpyderGST1
ID: 18069672
Actually the if, then statements is what I was looking for since I do need it to be more portable.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 125 total points
ID: 18069760
#!/bin/sh
cd /mnt/ABC/123 2>&1
if [ $? -ne 0 ]; then
  mount /mnt/ABC/123 || exit 42
fi
/path/to/another/script
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now