Redirect output of Whatsapp bash script to file interactively for automation purpose

2.3k Views Asked by At

Yowsup-cli is a library that can allow you to send message to whatsapp users,once authenticated. By the coommand

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config

I can interactively send or receive messages. Once executed the command you get a prompt like

[email protected] [27-12-2014 18:33]:THIS IS MY MESSAGE,TYPED ON MY PHONE. OPEN DOOR GARAGE Enter Message or command: (/available, /lastseen, /unavailable) I'm a totally beginner, but I would like to redirect this content that gets printed on terminal to a file,to further analyze it or to write a script that search into this file keyword as "OPEN GARAGE DOOR", so i could automate something. This file obviously has to sync with the program output,but I don't know how to do.

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config > /path/to/my_file doesn't work

Running Ubuntu 12.04. I know yowsup is a python library, but i don't know this language. I'm beginning learniing C and I would like to do that in BASH, or if not possible in C. Thanks

1

There are 1 best solutions below

7
On BEST ANSWER

Pipe the output into tee instead of redirecting it into a file:

yowsup-cli -a --interactive <PHONE_NUMBER_HERE> --wait --autoack --keepalive --config yowsup-master/src/yowsup-cli.config 2>&1 | tee -a /path/to/my_file

The reason: With redirection you don't see the command's output which makes interacting with it hard. Piping into the tee command will echo all output the the terminal and append it to given file.

Interestingly, in your command line (using redirection) you can still type blindly or even according to the yowsup-cli ouptut you read in another terminal with:

tail -f /path/to/my_file

Tail with the -f option prints the last 10 lines of the file as well as any new ouptut from the yowsup-cli command.