You are not logged in.
Pages: 1
Hi gues
I''m new in arche and generalny in linux .
Lately I wanted to automount my MP3 player when i plug in him.
Let's move to the point .
Firstly i writen script to mount
#!/bin/bash
sleep 10
echo "pawel" >> /home/lenovo/pawel.txt
/bin/mount -o ro /dev/sony_walkman /mnt/sony_walkman
exit
Next
My udev rule
SUBSYSTEM=="block", ATTRS{ventor}=="SONY", SYMLINK+="sony_walkman:, RUN+="/bin/sh -c 'sudo /home/lenovo/.scripts/mount_sony_walkman.sh'"
When i plug the mp3 player the script i called because the file pawel.txt is changed .
By disk is not mount
When i invoke the script in console than the disk is mounting.
Offline
You have not closed the quotes for SYMLINK+="..... <NO " HERE> (if that's clear
Also, ATTRS will match too many levels, make the rule specific to the appropriate level, then you won't need hacks like "sleep 10".
See example.
Last edited by brebs (2014-09-10 19:39:51)
Offline
Oh, and udev kills the shell after a few seconds, so your sleep(10) might prevent your script from doing anything before that time.
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
And finally - udev is the wrong tool for automounting removable drives. You need something based on udisks/udisks2.
This functionality is typically built in to DEs such as GNOME, KDE, etc, and smaller utilities such as udiskie can be used with slimmer setups.
Offline
Thanks for reply .
brebs
I am doing according with that you've written in example but nothing happend .
The disk isn't mounted.
I'am tired now , so maybe i do somethnig in wrong way . I will check once again tomorrow .
Member
that it means the script has to be short ?
Forum Fellow
I see , so generally i'd like to run any script when my device is plug in and it should not be removable
disk. I took it as example .
How can i achieve this without udev .
I think that I can write script whose check in some time interval if something appeared in /dev
If I would plugin the mp3 player and udev create symlink "sony_walkman" than my script
which is checking can react
I don't know if it is good idea , maybe there is better solution.
Last edited by ttmdear (2014-09-11 04:33:32)
Offline
I don't use it myself, but I think devmon can launch a command when a device is plugged in.
Offline
I wanted to automount my MP3 player when i plug in him
i'd like to run any script when my device is plug in
These are two different requirements - which one do you want?
BTW, "Member" and "Forum Fellow" are titles, not user names. It's customary to address people by their user name, as you managed to do with brebs.
Offline
I use a slightly better method these days, which is:
In /etc/udev/rules.d/10-local.rules
ACTION=="add", KERNEL=="sd*1", ATTRS{serial}=="BIGLONGLISTOFHEXCHARS", SYMLINK+="mydrive%n", RUN+="/root/bin/mntmydrive"
And that file contains, essentially:
if ! mountpoint -q /media/mydrive ; then
mount /media/mydrive
fi
And there's an appropriate entry in /etc/fstab, e.g.:
/dev/mydrive1 /media/mydrive vfat noauto,noatime,users,flush,gid=100,umask=007
If it doesn't work for you, do some debugging.
Remember to run this, after changing udev rules:
udevadm control --reload
Offline
Pages: 1