# devd and da* devices



## manefesto (Feb 20, 2011)

I want to run action if inserted flash drive
Edit devd.conf:

```
58 attach 0 {
 59     device-name "da[0-9]+";
 60     action "/home/sh/da.sh $device-name" ;
 61
 62 };
```
My simple script

```
#!/bin/sh
echo $1 >> /home/sh/out.txt
```

But nothing happens. Where's the bug?

PS: with umass worked fine.


----------



## wblock@ (Feb 20, 2011)

Is da.sh executable?


----------



## manefesto (Feb 20, 2011)

yes

```
chmod 777 da.sh
```
If change da to umass then fine worked,but need worked with da device


----------



## wblock@ (Feb 20, 2011)

Please don't use 777 as permissions.  That will come back to haunt you.  Or maybe someone else.

It seems that da devices don't trigger an attach event.  Maybe because they're not attached, but created.  You can detect them with a notify event from the devfs system:

```
# WB
notify 20 {
        match "system" "DEVFS";
        #match "subsystem" "CDEV";
        match "type" "CREATE";
        match "cdev" "da[0-9]$";
        action "/home/sampleuser/da.sh cdev=$cdev device attached!";
};
```

There's a corresponding destroy event on detach.  Because there may be multiple new devices created, da0 and da0s1 in my case, the pattern on the cdev line restricts that to just the um, base device.

The action script is run as root.  You can use su sampleuser -c '/home/sampleuser/da.sh ...' to run it as a less-dangerous user.

Thanks for asking this; it gave me a chance to find out some new things about devd(8).


----------



## manefesto (Feb 21, 2011)

Thanks, I was able to find a solution on their own,it is the same as yours


----------

