Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I am pretty new to linux and have been asked to write a script that will check all filesystems to see if they are read-only. I have come up ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    5

    Help with script to check if a filesystem is read-only


    Hi,

    I am pretty new to linux and have been asked to write a script that will check all filesystems to see if they are read-only.

    I have come up with ...

    df -h > /tmp/mount.lst
    awk '{print $6}' /tmp/mount.lst > /tmp/mounted_systems.lst

    This gives me ..

    Mounted
    /
    /boot
    /dev/shm
    /proc

    So now I have ..

    How do I automatically get rid of the 'Mounted' header in my /tmp/mounted_systems.lst file ?

    Also, I don't want to check the /proc filesystem, so how do I remove that within the script too.

    Then I will run ...

    while read dir
    do
    touch $dir/read_only_test
    done < /tmp/mounted_systems.lst

    If the filesystem is read only, I want that filesystem name to be listed into another file.

    Apologies if I am asking too much !

    Cheers

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    instead of creating a test file, the information you are looking for would be found in just mount command

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    5
    Ahh, better !
    What error would the mount command give if a file system was read only ?

    Cheers

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    mount command shouldn't throw error, it should only list information about mounted filesystems, I believe the keys you would be looking for would be rw, for writeable, and ro for readonly

  6. #5
    Just Joined!
    Join Date
    Jun 2013
    Posts
    1

    Arrow

    Quote Originally Posted by coopstah13 View Post
    mount command shouldn't throw error, it should only list information about mounted filesystems, I believe the keys you would be looking for would be rw, for writeable, and ro for readonly

    I do not believe that that is the case. Case in point:


    Code:
    [root@server logs]# touch file
    touch: cannot touch `file': Read-only file system
    
    [root@server logs]# mount
    .
    .
    /dev/mapper/Vol00_server-logs on /logs type ext3 (rw)
    .
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •