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. |
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 |
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 . |
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? |
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 |
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. |
which operating system are you using
If you execute the cron job as root user u do not need to add sudo |
Red hat Linux OS .
Is it? If i add to the crontab of root user then i no need to run as sudo. |
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. |
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" |
I think this will work bcos i tried in development server .I have to try in production server.
Thanks for your assistance. |
no problem ....
you can add me on gmail for quick assistance |
Can i have your email id please .Thanks
|
thanx
|
Thank you .I just send you an intro mail.
|
All times are GMT -5. The time now is 08:54 AM. |