LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-19-2013, 11:40 AM   #1
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
Need help with script to check all partitions


I want to write a script that will check all ext2/3/4 partitions with the command e2fsck. Following part detects and checks all partitions of type ext2/3/4:
Code:
while read dev _ 
do
   echo "ext partition found = $dev"
   e2fsck $dev
done <<< "$( blkid | grep 'TYPE="ext' | cut -d':' -f1 )"
How can I check if any of these partitions is mounted since it is not recommended to check mounted partitions? Or there is no need to modify this since the command e2fsck will not check a mounted partition? Thanks for your help.
 
Old 05-19-2013, 12:12 PM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
usually «mount» is used for that; say you'd like to know if /dev/sda1 is mounted:
Code:
$ dev=/dev/sda1 ; LC_ALL=C mount | cut -f1 -d" " | while read mp ; do test "$dev" -ef "$mp" && { echo "$mp" ; break ; } ; done
 
Old 05-19-2013, 08:39 PM   #3
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
I have to reach ' echo "$mp" ' if the partition is not mounted. I am not able to figure out how to do that. I tried: || instead of && and also test !(......) but it is not working since we need to compare 2 lists (one from blkid and other from mount command) and we need to pick out only those which are in blkid list but not in mount list.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Commands to check and change labels of partitions rng Linux - General 3 03-20-2013 10:01 AM
Script to check PID from file and check whether process is running or not rajkiran183 Linux - Newbie 5 10-19-2012 11:28 AM
How to check that my script can check if it has a specific range of charcters. shirlcurl20 Linux - Newbie 2 11-16-2010 11:15 PM
Moved file partitions, File system check failed on Fedora, Windows will not boot LinkSlayer64 Linux - Newbie 7 12-17-2009 02:18 AM
Resizing partitions - just check me on this one Proud Linux - General 18 04-17-2003 03:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:02 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