0

I need to write a bash script in a linux machine with the follow redirection.

echo commands > cmd_receives_commands > fifo > awk_parser > tcp_socket

I verified that for the "tcp_socket" works the construct:

echo 3<> /dev/tcp/address/port
cmd >&3
echo 3<&-

For the rest of the script I tried this:

mkfifo fifo

./parser.awk <&4 > out
exec 4>fifo
exec 3> >(cmd1 >&4)

echo to_cmd1 >&3
echo end $(date +%s) >&4
exec 3<&-
exec 4<&-

but they doesn't work, because the file out isn't written.

  • 1
    Is there a reason you can't use pipe like most people do? E.g., echo "this is a test \n this is only a test." | grep only | awk '{print $NF}' would print out "test." – jeremysprofile Jul 17 '18 at 16:11
  • Multiple Redirections in Command. This is why Linux have |[ Pipes ]| – C0deDaedalus Jul 18 '18 at 4:46
  • really there is a reason. in my example the step "cmd_receives_commands" is a proprietary command that, if run manually, returns a prompt. I also need to construct a loop for repete the same command (for monitoring) a lot of time and eventually intercept the output before the parser ( I thought with a tail in the fifo). – Ciccio Jul 18 '18 at 6:46
  • I finally understood my (big) fault. It's about fifo. Once readed the data are gone. – Ciccio Jul 18 '18 at 13:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.