Results 1 to 2 of 2
Dear All,
I have a usb to serial converter which i plug in to Ubuntu Natty.
I see that on every reboot this seems to come up as a different ...
- 05-19-2011 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 8
Shell script to find usb device name
Dear All,
I have a usb to serial converter which i plug in to Ubuntu Natty.
I see that on every reboot this seems to come up as a different device name, say ttyUSB0, ttyUSB3 etc.
I want to write a simple shell script to get the name of the device in a shellscript.
I have not written a shellscript before so can anyone help?
Thanks.
- 05-22-2011 #2Just Joined!
- Join Date
- May 2011
- Posts
- 44
Personally I would do it in Perl and not bash. Perl IMHO is easier to learn than bash. Not to mention I find it easier to read.
try something like this:
you could even put that into a commandline one liner:Code:#!/usr/bin/perl use strict; use warnings; my $dmesg = `dmesg`; my $port = $dmesg =~ m/(ttyUSB*+)/; print $port . "\n";
this is untested as I do not have a usb to serial readily available.Code:perl -e '$_ = `dmesg`; $port = m/(ttyUSB*+)/; print "$port \n";'


Reply With Quote