Results 1 to 3 of 3
I want to write a bash script that will launch a command when ever I plug my phone in. how would I monitor the port in a script....
- 05-15-2011 #1Linux Newbie
- Join Date
- Aug 2010
- Posts
- 133
[SOLVED] monitoring serial ports
I want to write a bash script that will launch a command when ever I plug my phone in. how would I monitor the port in a script.
- 05-16-2011 #2Just Joined!
- Join Date
- May 2009
- Location
- Oregon
- Posts
- 51
You have a couple of problems here. The first is detecting the plug in, and the second is determining what plugged in. I don't know what kind of phone you use, or how Linux recognizes it -- so I am just speaking in general.
On newer systems the /dev/ directory is dynamic. When a new port is plugged into USB, for example, an RS232 dongle -- it will show up as /dev/ttyUSB0 or 1,2,3,4,.... As long as the device is hot pluggable (USB) simply monitoring the /dev/ directory is a wasteful -- but simple way to write a script to detect a plug in (If you know the name).
Another way you could do this is to monitor dmesg or lsusb with grep or sed, periodically; or (though discouraged) /proc is another source of information.
For example, you could do:
while (true); do
sleep 2
if /sbin/lsusb | grep "Mitsumi" ; then echo "Mitsumi plugin detected."; break; fi
done
...
Where you tailor the grep command to detect the piece of hardware you are interested in.
Again, this is sloppy code -- but without knowing more detail about your Linux system and phone, I am not able to give anything but crude ideas of how to approach the problem.
- 05-16-2011 #3Linux Newbie
- Join Date
- Aug 2010
- Posts
- 133
I went a different rout and just launched a command and if my phone was plugged in it would work this seems to be working great for me. I put the script file into my startup applications It connects every time I plug so I think I'll leave it like this even if it is sloppy code.
code:
#/bin/bash
while :
do
command easytether connect
sleep 1
done



