Results 1 to 4 of 4

Thread: Bash scripting: feed etherwake program with text file

  1. #1
    Join Date
    Mar 2007
    Beans
    211

    Bash scripting: feed etherwake program with text file

    Hi all!

    I know this is a very stupid question for a programmer but I am not able to find a solution.

    I have a program: etherwake.

    It is used to wake on lan a PC using its mac address.

    I simply want to "feed" etherwake with a mac address contained in a text file.

    I've tried

    cat filename | etherwake

    etherwake < `cat filename`

    without any kind of luck...

    I always get:

    Specify the Ethernet address as 00:11:22:33:44:55

    Of course if I do a cimple cat filename I get a perfect mac address, without blank spaces or any kind of strange characters.

    What am I doing wrong?

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash scripting: feed etherwake program with text file

    try something like this
    Code:
    etherwake $( < filename )
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Bash scripting: feed etherwake program with text file

    You have to pass the mac address to etherwake as an option. So you can use command substitution:
    Code:
    etehrwake $(cat file)
    Or if you use BASH:
    Code:
    etehrwake $(< file)
    See:
    Code:
    man bash | less +/"^ +Command Substitution"
    and
    http://mywiki.wooledge.org/CommandSubstitution

    Pipes are used to connect the output of a command to the input of another one.
    http://mywiki.wooledge.org/BashGuide...ndOutput#Pipes

    If your command reads its input from stdin you can use < to redirect the content of a file to it:
    Code:
    command < file
    example:
    Code:
    read -r content < file
    echo $content
    See:
    http://mywiki.wooledge.org/Redirection

  4. #4
    Join Date
    Mar 2007
    Beans
    211

    Re: Bash scripting: feed etherwake program with text file

    God bless your help!

    I loved the solution and loved even more the explanation.

    You gave me a fish and taught me how to fish too...

    Thanks!

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
  •