Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:52:11+00:00 2026-05-28T03:52:11+00:00

This is a snippet from the middle of a bash script we use for

  • 0

This is a snippet from the middle of a bash script we use for monitoring the state of mounts on a server:

OIFS=$IFS
IFS=$'\n'
for mount in $mounts; do
        mountcount=$(($mountcount+1))
        dev=`echo $mount | awk {'print $1'};`
        dir=`echo $mount | awk {'print $2'};`
        opts=`echo $mount | awk {'print $4'};`
        state=`echo $opts | cut -d ',' -f 1`
        if [ "$state" = "ro" ]; then
                crit="true"
                break
        fi
done
IFS=$IFS

$mounts will have content similar to:

rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=1028136k,nr_inodes=218146,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
/dev/disk/by-uuid/f2337686-ec8d-429a-9002-592c564ddbf3 / ext3 rw,relatime,errors=remount-ro,barrier=0,data=ordered 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0
none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0

As you should be able to see, I am parsing to split each line out in to it’s components looking for mounts that are mounted read only. Functionally this works absolutely fine, however the problem is we are running this on 100s of servers, and currently it takes over a second (sometimes) to run through the above loop with the above data.

I believe this problem is caused by wait when executing awk and cut, as they are external programs, so I was wondering if there’s a more efficient way the same function could be achieved. I’m not quite proficient enough in bash to know the internal functions that might be able to help with this, or proficient enough in awk to do this all as one line.

My feeling is the 3 calls of awk and 1 call of cut could all be achieved in 1 line of awk. Any help greatly appreciated!

EDIT

The variables dev, dir and mountcount are used later in the script for building output.

EDIT

I’ve altered the script to the following: (All the echo’s are in there as a test)

mountcount=0

OIFS=$IFS
IFS=$'\n'
for mount in $mounts; do
    mountcount=$(($mountcount+1))
    echo $mount
    echo $mount | read dev dir fs opts
    echo $dev
    echo $dir
    echo $fs
    echo $opts
    state=`echo $opts | cut -d ',' -f 1`
    if [ "$state" = "ro" ]; then
        crit="true"
        break
    fi
done
IFS=$OIFS

And that gives me the following:

rootfs / rootfs rw 0 0




fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0




/dev/disk/by-uuid/1be5b3ae-8239-4177-9af6-22ad0afa662a / ext3 rw,relatime,errors=remount-ro,data=ordered 0 0




/dev/disk/by-uuid/1be5b3ae-8239-4177-9af6-22ad0afa662a /dev/.static/dev ext3 rw,relatime,errors=remount-ro,data=ordered 0 0




devpts /dev/pts devpts rw,relatime 0 0




securityfs /sys/kernel/security securityfs rw,relatime 0 0

So read isn’t work quite as expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:52:11+00:00Added an answer on May 28, 2026 at 3:52 am

    This might work for you:

    OIFS=$IFS; IFS=$'\n'; ma=($mounts); IFS=$OIFS
    mountcount=0
    for mount in "${ma[@]}"; do
        ((mountcount++))
        fa=($mount)
        dev=${fa[0]}
        dir=${fa[1]}
        opts=${fa[3]}
        state=${fa[3]/,*}
        if [ "$state" = "ro" ]; then
                crit="true"
                break
        fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I grabbed this snippet from another question: <script type='text/javascript' > $(document).ready(function () { $(div.content
I have this Perl snippet from a script that I am translating into Python.
This snippet from official website works as expected: $treeObject = Doctrine::getTable('Category')->getTree(); $rootColumnName = $treeObject->getAttribute('rootColumnName');
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
What's wrong with this snippet of code? import numpy as np from scipy import
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have this snippet from apple sample code LazyTableImages . In the code below
This snippet is from an earlier answer here on SO. It is about a
Can someone explain what the dict class is used for? This snippet is from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.