PDA

View Full Version : Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?


GigaByte
2011-09-06, 10:54
hey all,
I need to make a script which checks if the memory card is plugged in my N900, i.e. is mounted. It goes like...
if [ code to see if mmc card plugged in ]; then...

Yes, I am still at the learning phase and I tried searching lots of forums and other websites but no go, please HELP! the poor.:(

GigaByte
2011-09-06, 11:39
Bump.
I just want to know the command that checks if the mmc is plugged in or not :(

abill_uk
2011-09-06, 11:47
Sorry to see nobody answer you but you do not need a script to see if your SD card is plugged in or not because it is already built in to the OS.

Are you having problems seeing the sd card?.

abill_uk
2011-09-06, 11:56
You use the browser in your device to see it is there or not also you can use your pc browser to see it and write or mount whatever you want.

You need to be more specific to what problem your having.

stef
2011-09-06, 12:06
hi ithink this should help
$ mount | grep mmc1 | wc -l
if result>=1 , u r done

GigaByte
2011-09-06, 12:07
You use the browser in your device to see it is there or not also you can use your pc browser to see it and write or mount whatever you want.

You need to be more specific to what problem your having.

Yeah well. It's not like that.

I want to make script that does "something" when the sd card is plugged in, and another "thing" when it isn't plugged in.
For that to work, I need to implement a code in the script that checks if the memory card is in or not, to see what "thing" it shall do.

GigaByte
2011-09-06, 12:08
hi ithink this should help
$ mount | grep mmc1 | wc -l
if result>=1 , u r done

Thanks stef, will try that right now and report.

magick777
2011-09-06, 12:09
The list of what's mounted is /etc/mtab, and the mmc is /dev/mmcblk1p1.

So something like

TEST=`grep -o mmcblk1p1 /etc/mtab`;
if [ ! -z "$TEST" ]; then
# do something
else
# don't do something
fi

Edited to explain:

First line sets the variable $TEST with the output of the command that's in backticks. The grep command searches for the mmcblk1p1 in the list of what's currently mounted, the -o switch says output only what matched.

Then, in shell, if that gets us a non zero length response, well, we found what we were grepping for, if not we didn't...

GigaByte
2011-09-06, 12:11
hi ithink this should help
$ mount | grep mmc1 | wc -l
if result>=1 , u r done

Wow :D worked like a treat! thanks! :D

GigaByte
2011-09-06, 12:15
The list of what's mounted is /etc/mtab, and the mmc is /dev/mmcblk1p1.

So something like

TEST=`grep -o mmcblk1p1 /etc/mtab`;
if [ ! -z "$TEST"; then
# do something
else
# don't do something
fi

Edited to explain:

First line sets the variable $TEST with the output of the command that's in backticks. The grep command searches for the mmcblk1p1 in the list of what's currently mounted, the -o switch says output only what matched.

Then, in shell, if that gets us a non zero length response, well, we found what we were grepping for, if not we didn't...

This also worked great, huge thanks man.

p.s. You forgot a ] but never mind, got everything sorted now thanks

magick777
2011-09-06, 12:18
This also worked great, huge thanks man.

p.s. You forgot a ] but never mind, got everything sorted now thanks

Well caught. I've corrected the post for anyone who stumbles on it later. :-)

magick777
2011-09-06, 12:26
It occurs to me that you can save yourself the grep and just check for the readability of a specific path that won't exist unless the SD card is mounted.

if [ -r "/media/mmc1/systemBackups" ]; then

It may make more sense to check for the path you want to operate on than to check for the mere existence of a microSD. Oh, and if you ever need to know what you've physically got on the system BEFORE it gets mounted, you could try /proc/partitions.

stef
2011-09-06, 12:56
sure,
cat /proc/partitions | grep mmcblk1 | wc -l
u r done too, and you know how much partitions u have ;-) on the SD card :-p

chris_r
2011-09-18, 21:17
or just "df" and see if /dev/mmcblk1p1 is mounted anywhere. It should be /media/mmc1/