Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Just 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:
    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my $dmesg = `dmesg`;
    my $port = $dmesg =~ m/(ttyUSB*+)/;
    print $port . "\n";
    you could even put that into a commandline one liner:
    Code:
    perl -e '$_ = `dmesg`; $port = m/(ttyUSB*+)/; print "$port \n";'
    this is untested as I do not have a usb to serial readily available.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...