LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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, 10:05 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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

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 12:04 AM.
 
Old 01-13-2012, 12:26 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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, 09:52 AM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

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, 10:25 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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



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 02:44 PM
display erro log in linux using shell script venu_babu Programming 1 08-31-2008 03:01 PM
How to use GFS 6.1 to read a mount point that accesses multiple devices aqhaone Linux - Server 0 05-15-2008 11:03 AM
shell script - monitor mount point noir911 Programming 1 03-20-2008 06:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:35 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
Open Source Consulting | Domain Registration