2 thoughts on - CentOS 7 Bash Perhaps Off Topic

  • So you are saying that the actual “while read line do ….. done ….” is what is failing?Try sending the output of the smwebsocket “$URL” | grep Location so we may see what is being passed to the while read line. Additionally you could use sh -x to execute it and it may show something. You could send the code exactly also.K
    On ‎Monday‎, ‎November‎ ‎26‎, ‎2018‎ ‎03‎:‎11‎:‎14‎ ‎PM‎ ‎EST, Jerry Geis wrote:

    hi all,

    I have a small script that seems to be exiting and hitting the sleep 60… The smwebsocket just connects to the web socket provided and outputs the data. This works manually.

    the myprogram just opens a database and writes the line…

    My desire is to run the smwebsocket, connect to the websocket and output the data (line by line) when we get a line that matches Location take that line and output to the database. Seems simple. I desire this to keep the connection alive and just continue to read data and grep on the data etc… if smwebsocket does exit, sleep 60 and reconnect.

    However it seems to be exiting and running the sleep 60. Am I missing something ?

    while [ 1 ]
                    do
                            smwebsocket “$URL” | grep Location | while read line
                            do
                                    myprogram -data “$line”
                            done

                    sleep 60
                    Reconnecting…
                    done

    All the pieces work – just not the actual running.  What am I missing?

    Jerry

  • If I’m understanding you corectly, you want smwebsocket to continuously pull data passing it to grep for filtering and ultimately to myprogram to update a database. If that’s correct I haven’t had an opportunity to work with that but my current understanding of how pipelining works is that smwebsocket would retrieve $URL (which would be a finite amount of data), it would end sending output to grep which would filter it (and end) sending its output to the while loop around myprogram which would process it until there was no more data (and end) thus landing at ‘sleep 60’ only to start over again. If a pipeline is capable of continuous processing I’m not aware of it (but would be glad to know that’s how it can work).

    Leroy Tennison Network Information/Cyber Security Specialist E: leroy@datavoiceint.com
    2220 Bush Dr McKinney, Texas
    75070
    http://www.datavoiceint.com TThis message has been sent on behalf of a company that is part of the Harris Operating Group of Constellation Software Inc. These companies are listed here
    . If you prefer not to be contacted by Harris Operating Group please notify us
    . This message is intended exclusively for the individual or entity to which it is addressed. This communication may contain information that is proprietary, privileged or confidential or otherwise legally exempt from disclosure. If you are not the named addressee, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this message in error, please notify the sender immediately by e-mail and delete all copies of the message.