LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 01-12-2012, 10:24 PM   #1
monty_0309
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Rep: Reputation: 0
Shell script to display Read Only (ro) mount point in Linux


Hi,

I want a Shell script to display Read Only (ro) mount point in Linux machine.

Some suggesstions.

Regards,
Vaibhav
 
Old 01-12-2012, 11:05 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
What have you got so far?
 
Old 01-13-2012, 01:00 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
Had some free time Here ya go ,have fun.

Quote:
#!/bin/bash

#Author:Cbtshare aka stainless
#Purpose:Checks if a mount point on your system is in READ-ONLY mode

mount | awk '{print $1 " " $6}' |

while read output;
do

RW=$(echo $output | cut -d "(" -f 2 | sed -n 's/\(ro\).*/&/p'| cut -d "," -f 1)

FILESYSTEM=$(echo $output | cut -d " " -f 1)


if [ "$RW" = "ro" ]

then

echo "$FILESYSTEM is READ-ONLY"

else

echo $FILESYSTEM is WRITEABLE
fi


done

Last edited by cbtshare; 01-13-2012 at 01:04 AM.
 
Old 01-13-2012, 01:26 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Normally, I don't like trying to shove lots of functionality into a hard-to-read command, but I was interested in the challenge (and I couldn't sleep).

So, this works on my system:
Code:
mount | sed -n 's@.* on \([^ ]\+\) .*\((\|,\)ro\(,\|)\).*@\1@p'
I was inspired to try when I saw cbtshare's script using sed
 
Old 01-13-2012, 10:52 AM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
Quote:
Originally Posted by Dark_Helmet View Post
Normally, I don't like trying to shove lots of functionality into a hard-to-read command, but I was interested in the challenge (and I couldn't sleep).

So, this works on my system:
Code:
mount | sed -n 's@.* on \([^ ]\+\) .*\((\|,\)ro\(,\|)\).*@\1@p'
I was inspired to try when I saw cbtshare's script using sed
lol this works great too.I guess your a master on sed,this was my first time using it lol..good job,nice share
 
Old 01-14-2012, 11:25 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
mount | awk '( $NF ~ /[,(]ro[,)]/) { print $3 }'
This assumes that the path names don't contain spaces however, as that would mess up awk's field counting. You'd have to loop through the line to print the fields between "on" and "type" for that.

Code:
mount | awk '{ if ($NF ~ /[,(]nosuid[,)]/) { for (i=1;i<=NF;i++) { if ($i == "on") { x=1; continue }; if ($i == "type") { x=0; break }; if (x == 1) { printf "%s", $i } } printf "\n" } }'
Not very neat as a one-liner though. It reads better as a stand-alone script. Could probably be simplified some too.
 
  


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
command to display the device-fs-uuid-mount point htamayo Linux - Newbie 2 10-26-2010 03:44 PM
display erro log in linux using shell script venu_babu Programming 1 08-31-2008 04:01 PM
How to use GFS 6.1 to read a mount point that accesses multiple devices aqhaone Linux - Server 0 05-15-2008 12:03 PM
shell script - monitor mount point noir911 Programming 1 03-20-2008 07:44 PM


All times are GMT -5. The time now is 04:54 PM.

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