# How to debug shell commands

**URL:** <https://forum.ansible.com/t/how-to-debug-shell-commands/11442>\
**Category:** Ansible Project\
**Created:** [April 24, 2012, 8:02pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442 "2012-04-24T20:02:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Art\_Zemon](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Art\_Zemon](https://forum.ansible.com/u/Art_Zemon)\
**Post date:** [April 24, 2012, 8:02pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/1 "2012-04-24T20:02:05Z")

</div>

I tried a command with the shell and it just hung:

> ansible -D -i server.lst [cloud1.hens-teeth.net](http://cloud1.hens-teeth.net) -m shell -a ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

No output at all. More on that in a bit.

It works fine with ssh:

> ssh [cloud1.hens-teeth.net](http://cloud1.hens-teeth.net) ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

Which led me to wondering about how to debug something like this. I had hoped that -D would give me something to work with but I got nada. Short of diving into the Python code and adding print statements, do you have suggestions?

Returning to the command that I wanted to run, I think that it is waiting for a password to be entered. It I put some backslashed in front of the dollar sign, I get different output. I haven’t found a quantity of backslashed that work. How many do you think I should have?

Thanks,  
– Art Z.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 24, 2012, 8:30pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/2 "2012-04-24T20:30:00Z")

</div>

> I tried a command with the shell and it just hung:
> 
> > ansible -D -i server.lst [cloud1.hens-teeth.net](http://cloud1.hens-teeth.net) -m shell -a ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’
> 
> No output at all. More on that in a bit.

> It works fine with ssh:
> 
> > ssh [cloud1.hens-teeth.net](http://cloud1.hens-teeth.net) ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’
> 
> Which led me to wondering about how to debug something like this. I had hoped that -D would give me something to work with but I got nada. Short of diving into the Python code and adding print statements, do you have suggestions?

-D provides module debug output only.

> Returning to the command that I wanted to run, I think that it is waiting for a password to be entered. It I put some backslashed in front of the dollar sign, I get different output. I haven’t found a quantity of backslashed that work. How many do you think I should have?

Ansible shouldn’t ask for a password unless you use --ask-pass. Note that ansible is trying root unless you pass in “-u” to ansible.

This should of course immediately die, not hang.

Sudo may hang if you were using --sudo, at least in 0.3 implementations.

---

<div class="post-metadata">

**Author:** ![Art\_Zemon](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Art\_Zemon](https://forum.ansible.com/u/Art_Zemon)\
**Post date:** [April 24, 2012, 9:47pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/3 "2012-04-24T21:47:58Z")

</div>

Michael,

ansible wasn’t waiting for a password. I think that mysqlcheck was waiting for a password. I think that

> $(cat /etc/psa/.psa.shadow)

evaluated to an empty string, which would make mysqlcheck prompt for a password.

Is there a way to get

> /usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases

to run properly in the shell module? I enclosed the whole thing in single quotes and tried 0, 1, 2, 4, 6 and 8 backslashes in front of the dollar sign. None worked.

With ssh, it’s easy. Just type:

> ssh [cloud1.hens-teeth.net](http://cloud1.hens-teeth.net) ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

No backslashes needed at all.

– Art Z.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 24, 2012, 10:02pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/4 "2012-04-24T22:02:57Z")

</div>

your local shell MAY be eating things. Try escaping the $?

---

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [April 24, 2012, 10:05pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/5 "2012-04-24T22:05:34Z")

</div>

in lieu of $(stuff)

try:

`stuff`

I've found backticks are easier to swallow by the shell.

-sv

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 24, 2012, 10:09pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/6 "2012-04-24T22:09:41Z")

</div>

Oh, you WANT the shell to evaluate that locally. Interesting.

---

<div class="post-metadata">

**Author:** ![Art\_Zemon](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Art\_Zemon](https://forum.ansible.com/u/Art_Zemon)\
**Post date:** [April 25, 2012, 12:18pm UTC](https://forum.ansible.com/t/how-to-debug-shell-commands/11442/7 "2012-04-25T12:18:31Z")

</div>

Seth: I’ll try backticks and see if it works better.

Michael: No, I want the command executed remotely, not locally.

BTW, I do understand that I am moving afield from “configuration management” into “system management” and that this is not what ansible is intended to do. I was just playing with using ansible in lieu of pssh and hit this curiosity.

– Art Z.
