maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   OS2008 / Maemo 4 / Chinook - Diablo (https://talk.maemo.org/forumdisplay.php?f=29)
-   -   How to automatically run a script when SD is mounted? (https://talk.maemo.org/showthread.php?t=23143)

iamthewalrus 2008-08-25 11:28

How to automatically run a script when SD is mounted?
 
Hi all,

In order to find the cause of reboot loops I installed syslogkd. I can let it write logs to one of the SD cards. But after rebooting no new logs are written to it. I guess this is because the daemon tries to write the files before the SD card is mounted.

So my next idea was to automatically copy the logfiles from /var/log/ to the SD card as soon as it is mounted. But it won't work so far. To test using udev for this I have made these files:

/etc/udev/rules.d/91_backupsyslogs.rules :
Code:

KERNEL=="mmc1", RUN+="/usr/local/bin/backup_syslogs.sh"
/usr/local/bin/backup_syslogs.sh :
Code:

#!/bin/sh
if [ "${ACTION}" = "add" ] then
    datestring=`date '+%Y%m%d_%H%M%S'`
    echo "" > "/media/mmc1/test_${datestring}"
fi

When removing and inserting mmc1, or after rebooting no 'test..' file gets written to it like I would expect. Am I using the wrong string from "udevinfo -a -p /sys/block/mmcblk1" to test for in the .rules file? I have set the executable permission to both files. Are there better ways to do this?

qwerty12 2008-08-25 11:43

Re: How to automatically run a script when SD is mounted?
 
To answer the topic question:

If the card is a vfat card, edit /usr/sbin/mmc-mount and put "exec /usr/local/bin/backup_syslogs.sh" at the end. If it's an ext* one, edit /usr/sbin/osso-mmc-mount.sh and find the right section depending on fs to shove that line in.

iamthewalrus 2008-08-25 11:59

Re: How to automatically run a script when SD is mounted?
 
Quote:

Originally Posted by qwerty12 (Post 217216)
To answer the topic question:

If the card is a vfat card, edit /usr/sbin/mmc-mount and put "exec /usr/local/bin/backup_syslogs.sh" at the end. If it's an ext* one, edit /usr/sbin/osso-mmc-mount.sh and find the right section depending on fs to shove that line in.

That worked, thanks! Still it's curious that the udev method doesn't.

fanoush 2008-08-25 12:57

Re: How to automatically run a script when SD is mounted?
 
Quote:

Originally Posted by iamthewalrus (Post 217220)
Still it's curious that the udev method doesn't.

Maybe mmc0 instead of mmc1 would work?

iamthewalrus 2008-08-25 13:13

Re: How to automatically run a script when SD is mounted?
 
Quote:

Originally Posted by fanoush (Post 217228)
Maybe mmc0 instead of mmc1 would work?

That has no effect. Also I have an n800 with both SD cards inserted and the bug you linked to manifests itself only when one card is removed.

fanoush 2008-08-25 13:33

Re: How to automatically run a script when SD is mounted?
 
Quote:

Originally Posted by iamthewalrus (Post 217229)
the bug you linked to manifests itself only when one card is removed.

This is correct for N800. On N810 it manifests itself only when external card is inserted (slots are physically swapped). Anyway, it doesn't matter here.

iamthewalrus 2008-08-25 15:15

Re: How to automatically run a script when SD is mounted?
 
Calling my script from '/usr/sbin/mmc-mount' with 'exec' caused 'memory card corrupted or unformatted' error popups. Without 'exec' and with the output suppressed it works:
Code:

sh /usr/local/bin/backup_syslogs.sh &> /dev/null
I'll also try the sp-rich-core core-dump tool.

TA-t3 2008-08-25 15:40

Re: How to automatically run a script when SD is mounted?
 
You definitely don't want the 'exec' there.. it replaces the process (the original script) with the one you're calling, which isn't what you want to do - you just want to call that backup_syslogs.sh script and then go on with the original script (even if that's just to exit, if you placed that call at the end).

Just
Code:

/usr/local/bin/backup_syslogs.sh &> /dev/null
should be OK, if the backup_syslogs.sh script begins with
Code:

#!/bin/sh
and has the 'x' bit set (chmod a+x backup_syslogs.sh), unless you have /usr/local/bin on a vfat card, as those are mounted noexec. For such cases (no x-bit or noexec), using 'sh' to execute the script (as in your posting) will handle that.


All times are GMT. The time now is 06:42.

vBulletin® Version 3.8.8