maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Newbie (https://talk.maemo.org/forumdisplay.php?f=26)
-   -   Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not? (https://talk.maemo.org/showthread.php?t=76349)

GigaByte 2011-09-06 10:54

Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
hi ithink this should help
$ mount | grep mmc1 | wc -l
if result>=1 , u r done

GigaByte 2011-09-06 12:07

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
Quote:

Originally Posted by abill_uk (Post 1082803)
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
Quote:

Originally Posted by stef (Post 1082804)
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
The list of what's mounted is /etc/mtab, and the mmc is /dev/mmcblk1p1.

So something like

Code:

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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
Quote:

Originally Posted by stef (Post 1082804)
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

Re: Newbie simple HELP! in Scripting! How to check if mmc card is mounted or not?
 
Quote:

Originally Posted by magick777 (Post 1082809)
The list of what's mounted is /etc/mtab, and the mmc is /dev/mmcblk1p1.

So something like

Code:

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


All times are GMT. The time now is 21:35.

vBulletin® Version 3.8.8