LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2012, 11:31 PM   #1
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
Question Shell script to mount SAN


Hi experts,
Greetings.
I am a newbie in linux and i have to write a shell script to include the mount command to mount the SAN.
I dont know how to run the command as super user.Can anyone please help me by providing the shell script to do so.
Actually the shell script should check whether SAN is mounted and if not mount the SAN

Sample;
mount /dev/sda1 /iscsi/vol01

This is the command .I dont know how to include it in shell script and put it in cron .So the shell script should not ask for superuser password at runtime.

Please help me by giving your valuable suggestions and ideas.

Thanks in advance.
 
Old 09-26-2012, 01:57 AM   #2
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
Hi User

you can start with something like this .
create a file enter the code below and give it executable permission


#!/bin/bash
FS="/dev"

if cat /proc/mounts | grep -F "$FS" > /dev/null; then
echo " Filesystem is mounted"
else
echo " Filesystem is not mounted"
fi
 
Old 09-26-2012, 02:24 AM   #3
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
So many Thanks for your reply.

i think this code only checks whether it is mounted or not .
I want code to mount it if the one is not mounted.
Please help me to provide the code to mount it .

thanks in advance .
 
Old 09-26-2012, 02:35 AM   #4
sackboy
LQ Newbie
 
Registered: Sep 2012
Posts: 20

Rep: Reputation: Disabled
You should be creating this script as the super user (root).

If you insist on doing it as an unprivileged user, you'll need to:
1) allow passwordless sudo access to the command you want to run
2) create a script that runs the mount command through sudo

Why do you want to mount using an unprivileged user anyway?
 
Old 09-26-2012, 02:43 AM   #5
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
I agree with sackboy,

why do you need to mount using a unprivileged user?
execute the above script
just add the mount command to it that all i guess it should work fine, if nay issue post back
 
Old 09-26-2012, 02:47 AM   #6
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
I want to put the script in cron so that it will run automatically.So i want to include the mount command as sudo command .
But i dont know how to implement it.
 
Old 09-26-2012, 03:00 AM   #7
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
which operating system are you using

If you execute the cron job as root user u do not need to add sudo
 
Old 09-26-2012, 03:21 AM   #8
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Red hat Linux OS .

Is it? If i add to the crontab of root user then i no need to run as sudo.
 
Old 09-26-2012, 03:24 AM   #9
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
So can i have my code as below

#!/bin/bash
FS="/dev/sda1"
if cat /proc/mounts | grep -F "$FS" > /dev/null; then
echo " Filesystem is mounted"
else
mount /dev/sda1 /iscsi/vol01
fi

and add this script to root user crontab ?


Thanks in advance for all experts.
 
Old 09-26-2012, 03:26 AM   #10
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
yes!

login as root and add the job to its crontab it will mount at the specified time

if you want to auto mount on boot then add the mount point to fstab file located at /etc/fstab, please provide the exact parameters there

if you find this helpful please "Rep"
 
1 members found this post helpful.
Old 09-26-2012, 03:29 AM   #11
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
I think this will work bcos i tried in development server .I have to try in production server.

Thanks for your assistance.
 
Old 09-26-2012, 03:41 AM   #12
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
no problem ....

you can add me on gmail for quick assistance
 
Old 09-26-2012, 04:39 AM   #13
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Can i have your email id please .Thanks
 
Old 09-26-2012, 05:20 AM   #14
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
thanx

Last edited by fernfrancis; 09-27-2012 at 01:23 AM.
 
Old 09-26-2012, 05:36 AM   #15
linux_new_bie
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thank you .I just send you an intro mail.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to display Read Only (ro) mount point in Linux monty_0309 Linux - Newbie 5 01-14-2012 11:25 AM
Assistance in Shell script on placing files across mount points. manickaraja Programming 15 02-27-2010 03:53 AM
shell script - monitor mount point noir911 Programming 1 03-20-2008 07:44 PM
Shell script can't mount using CIFS James H Red Hat 2 02-18-2008 08:17 AM
Fail to mount a path in SAN sunhui Linux - Hardware 3 03-28-2007 11:53 PM


All times are GMT -5. The time now is 11:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration