Answer the question
In order to leave comments, you need to log in
Need help with redirection in bash. Where to dig?
Good afternoon! The task is simple, and everything should theoretically work, but it does not work out a little.
There is a bash script, it has one variable. It is
necessary to take a txt file from the server and parse this variable using the pipe of commands that are written in this file
. In the console, I do this:
asterisk -rx 'gsm send ussd 1 *112*1#' | cut -d' ' -f2 | tail -n 1 | awk -F ":" '{print $1}'
1156
cut -d' ' -f2 | tail -n 1 | awk -F ":" '{print $1}' и помещаю в файл на сервере http://192.168.240.47/ussdkstregexp.txt
asterisk -rx 'gsm send ussd 1 *112*1#' | `wget -qO- http://192.168.240.47/ussdkstregexp.txt`
Answer the question
In order to leave comments, you need to log in
Yaroslav, when you execute a command
, the wget program (GNU Wget is a free utility for non-interactive download of files from the Web) downloads the specified file from the web server, and, taking into account the -O- switch, outputs its contents to standard output (stdout) .
Therefore, if you want to use the received data, downloaded from a file on the web server, and output to stdout, then simply pipe the output of wget to the following command through the pipeline:
wget -qO- http://192.168.240.47/ussdkstregexp.txt | next_command
IMHO it's a big perversion to make tricky *** one-liners, although theoretically you can make such a one-liner by cheating with streams.
minus one, few people will understand it, and in a month you yourself will be thinking "what did I do"
maybe just asterisk -rx 'gsm send ussd 1 *112*1#' | cut -d' ' -f2 | tail -n 1 | awk -F ":" '{print $1}' put into a file,
then you can download it and redirect it to bash, bash will process the commands from the stream.
it will be much easier to understand the work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question