skip to Main Content

I want to send the stdout and stderr of terminal while I run a huge batch file. The batch file
echoer.sh

echo $HOME
sleep 3
echo $HOME
sleep 3
echo $HOME
# n times

Executing in terminal

./echoer.sh | redis-cli -x publish echoer

This waits for the entire execution of echoer.sh to finish and then send the publish command. Is there a way to publish the output as soon as you receive it?

Current Output

# command
redis-cli subscribe echoer
# output below
1) "message"
2) "echoer"
3)"/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn/home/prashantn

2

Answers


  1. Sure, read the output of your script one line at a time and then publish that line to Redis:

    ./echoer.sh | while read line ; do echo "$line" | redis-cli -x publish echoer ; done 
    
    Login or Signup to reply.
  2. Using xargs , it sends each line to echoer channel using xargs utility.

     ./echoer.sh| xargs -n 1 redis-cli  publish echoer
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search