# problem  when I want to run a shell program on remote host in background

**URL:** <https://forum.ansible.com/t/problem-when-i-want-to-run-a-shell-program-on-remote-host-in-background/30317>\
**Category:** Ansible Project\
**Created:** [May 13, 2019, 2:18pm UTC](https://forum.ansible.com/t/problem-when-i-want-to-run-a-shell-program-on-remote-host-in-background/30317 "2019-05-13T14:18:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nguyen\_Hoang](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@Nguyen\_Hoang](https://forum.ansible.com/u/Nguyen_Hoang)\
**Post date:** [May 13, 2019, 2:18pm UTC](https://forum.ansible.com/t/problem-when-i-want-to-run-a-shell-program-on-remote-host-in-background/30317/1 "2019-05-13T14:18:18Z")

</div>

Hi Ansible Experts!

I use ansible 2.4.2.0 on linux Centos

I have one problem when I want to run a shell program on remote host in background

I have a shell program **ControllerAgent** like that :

[root@157501lepca02 bin]# pwd  
/home/neoload69/bin  
[root@157501lepca02 bin]# ls -l  
total 320  
-rwxr-xr-x 1 root root 13698 7 mars 09:04 **ControllerAgent**  
…

If I run manually my shell program ControllerAgent as following :

[root@157501lepca02 bin]# nohup /home/neoload69/bin/ControllerAgent \</dev/null \>/dev/null 2\>&1 &  
[1] 10147  
[root@157501lepca02 bin]#

it works well

But when I want to run my shell program ControllerAgent in a ansible playbook as following :

- hosts: [xx.yyy.tt.xxx]  
become: yes  
remote\_user: deploy75  
…

- name: Starting Controller Agent  
shell: sh nohup /home/neoload69/bin/ControllerAgent \</dev/null \>/dev/null 2\>&1 &

…

Nothing happens, it means that no process of my shell program ControllerAgent is created

Do you have an idea of the problem to help me ?

Thanks a lots

Best regards

Viet

NB : the remote user deploy75 is in the visudo file of the remote machine xx.yyy.tt.xxx like

## Allow root to run any commands anywhere

root ALL=(ALL) ALL  
deploy75 ALL=(ALL) ALL

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 13, 2019, 2:23pm UTC](https://forum.ansible.com/t/problem-when-i-want-to-run-a-shell-program-on-remote-host-in-background/30317/2 "2019-05-13T14:23:30Z")

</div>

You are calling sh while shell already does this, also the nohup is  
inside the sh so it won't prevent the disconnection race condition,  
you need to execute the nohup directly:

shell:nohup /home/neoload69/bin/ControllerAgent \</dev/null \>/dev/null 2\>&1 &

Also, I don't recommend doing this if you really want to run  
backgrounded services like this you should use a service manager  
(init.d, systemd, runit, upstart, etc)

---

<div class="post-metadata">

**Author:** ![Nguyen\_Hoang](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@Nguyen\_Hoang](https://forum.ansible.com/u/Nguyen_Hoang)\
**Post date:** [May 13, 2019, 8:21pm UTC](https://forum.ansible.com/t/problem-when-i-want-to-run-a-shell-program-on-remote-host-in-background/30317/3 "2019-05-13T20:21:10Z")

</div>

Hi Brian

I have just done what you advice me

and it works, it is ok now

Thanks a lot

Best Regards

Nguyen
