How to use piping multiple shell commands

96 views
Skip to first unread message

Veera

unread,
Jul 31, 2019, 11:01:19 PM7/31/19
to Ansible Project
Hi,

I am trying the below   snippet to  detect  the established ports.  but Ansible throws an error.

 - name: List the  port connections
      shell
: "netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"
      register: dc_stat
      debug:
        var: dc_stat.stdout_lines

this through's the error

The offending line appears to be:


   
- name: List the  port connections
      shell
: netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"
                                                                                 
^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes
.  If starting a value with a quote, make sure the
line ends
with the same set of quotes.  For instance this arbitrary
example
:


    foo
: "bad" "wolf"


Could be written as:


    foo
: '"bad" "wolf"'



I tried  inserted  a " " for the shell commands  and using  vars/pipe also .. 
How can i direct the output of "netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"" to a variable  ?

Or  do we have to use backslash(\)  as in shell ?


vinoth kumar

unread,
Jul 31, 2019, 11:28:17 PM7/31/19
to ansible...@googlegroups.com
Error clearly says to use proper quotes 

‘netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"’ 
Save it in Regiter
Use set_facts to store as a variable 


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3e2a9fa0-7974-4455-baa6-f45b2f690aae%40googlegroups.com.

vinoth kumar

unread,
Jul 31, 2019, 11:29:32 PM7/31/19
to ansible...@googlegroups.com
On Thu, 1 Aug 2019 at 8:57 AM, vinoth kumar <vinod...@gmail.com> wrote:
Error clearly says to use proper quotes 
This would be fine i think so 
“netstat -nautp |grep -iE ‘137|389|445|636’|awk '{print $5}' |cut -d: -f2 |grep -iwE ‘137|389|445|636’”

Veera

unread,
Aug 1, 2019, 8:57:22 AM8/1/19
to Ansible Project
Thanks Vinoth.  It worked

Yes . I learnt that we can use the formatting as in python either with ' '  or  " ".



To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages