Results 1 to 2 of 2

Thread: when gets the hardware address of network card determined

  1. #1
    Join Date
    Sep 2011
    Beans
    19

    when gets the hardware address of network card determined

    hello

    i have trouble to get a bash script working. the bash script gets launched from rc.local.
    and it should run only one time after a clonezilla image restore (when the pc gets booted for the first time after the image restore).

    one part of the bash script is to read the hardware address using ifconfig:

    HTML Code:
    mac=$(/sbin/ifconfig | grep ^eth* | tr -s ' ' | cut -d' ' -f6 | tr "[a-z]" "[A-Z]")
    the problem is i always get en empty string, if the script is launched during the boot process (launched by rc.local). if i launch the script in a terminal (as user root) by myself, the variable ${mac} holds the hardware address (and isn't empty).

    further in rc.local i tried to set:

    HTML Code:
    ( sleep 60 && /run/bash/script )
    it didn't help either.

    then i created in the script a while loop

    HTML Code:
    # create empty mac string
    mac=""
    
    while [ -z "${mac}" ]
    do
            mac=$(/sbin/ifconfig | grep ^eth* | tr -s ' ' | cut -d' ' -f6 | tr "[a-z]" "[A-Z]")
            sleep 10
    
           ... some code ...
    
    done
    it din't help either. in the task manager i see the script (with the loop from above) is running all the time but the string in "${mac}" is always an emtpy string.

    then i can copy/paste the code

    HTML Code:
    mac=$(/sbin/ifconfig | grep ^eth* | tr -s ' ' | cut -d' ' -f6 | tr "[a-z]" "[A-Z]")
    into a terminal and execute it (while the script is still running and returns empty strings) an i get the hardware address extracted.

    does anybody have an idea why the script returns empty strings?
    is there another way to get the hardware address from an ethernet card?

    kind regards, go4unkwn.

  2. #2
    Join Date
    Sep 2011
    Beans
    19

    Re: when gets the hardware address of network card determined

    Find a simple solution to my ifconfig problem (extract hardware address).

    I replaced ifconfig with ethtool and everything works fine.

    kind regards, go4unkwn

Tags for this Thread

Bookmarks

Posting Permissions

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