Using output of awk to run command

前端 未结 3 1763
终归单人心
终归单人心 2021-02-05 02:39

I am brand new to shell scripting and cannot seem to figure out this seemingly simple task. I have a text file (ciphers.txt) with about 250 lines, and I would like to use the fi

3条回答
  •  我寻月下人不归
    2021-02-05 03:35

    there are quite a few things wrong with your command. For one you want to use the first column. That's referred to as $1 in awk and not $0 (which would be the whole line). Second, you forgot a semicolon at the end of your definition of command.

    To actually run the command you can either use system() or a pipe (the latter only makes sense if the command can read from stdin, which openssl in your case won't, I think). The easiest would be something like

    awk '{cmd="openssl s_client -connect host:port -cipher" $1; system(cmd)}' results.txt
    

    Note, that this will only return the exit status. If you need to capture stdout, you will have to pipe the command through getline.

    Andreas

    PS: Posting the actual error you got, would have helped.

提交回复
热议问题