Jump to content

Launching bash script from Alfred doesn't always remove it from process list after terminating


Recommended Posts

I have a bash script (lets call it script.sh) 

It launches an ssh session to one of my LAN servers...

 

---

#/bin/sh 

ssh root@nelson

---

 

I have Alfred set up to allow me to launch this script directly..

This was done by adding 'public.shell-script' into Default Results -> Advanced (just by dragging that script into the pane)

 

Now, when I launch my SSH session from Alfred in this way, and then exit it by closing the iTerm2 tab, the ssh session remains in the process indefinitely (as a terminated process).

 

If instead, I end the ssh session by typing 'exit' then it is removed from the process list (as it should be).

Finally, if I launch the script manually from within iTerm (without using Alfred), then likewise it is removed from the process list when it ends

 

I cant say for certain whether its an Alfred bug or an iTerm2 bug, but my hunch is it might be a combination of the two, but it only manifests itself when launching a script from Alfred.

I only noticed this because I had over 300 terminated ssh sessions in 'ps aux', some dating back a couple of months ago

 

iTerm2 is *not* configured to use tmux, which would have explained one possible reason why this might happen

Should I be launching ssh from my script in a different way?

Any ideas what could be causing this? 

 

Finally you might ask why I launch a script which simply opens an ssh session

But in reality the script is much more complex. I've just boiled it down to the simplest way to be reproducable

 

Using OSX: 10.11.5 (El Capitan)

Alfred: v3.0.3 [694] Powerpack

 

Thanks
Edited by paulc
Link to comment

I launch script.sh directly from Alfreds results window (no workflows or anything, just a straight up Alfred search result)

 

This opens ITerm and runs script.sh (which in turns runs ssh root@nelson)

(So yes, I assume iTerm is the default application for shell scripts)

 

I am now left with an interactive ssh session in iTerm, so far so good.

 

At this point I close the iTerm tab using CMD + W

But the problem is the ssh session is left in the process list indefinitely 

 

ie, if I open a local cmd prompt, and...

 

"ps aux | grep nelson"

 

It will show one new zombied ssh session in the process list, for each time I repeat these steps

 

Even quitting iTerm completely will not clear these processes, which makes me think Alfred is at least playing some role in this bug

Edited by paulc
Link to comment

If you're using the default launch mechanism, it seems unlikely that Alfred is involved.

 

Alfred asks the system to open the script (as it does with every kind of file), and by default when you open a script in iTerm, it essentially just pastes "/path/to/the/script.sh; exit" into the shell.

 

There might be something funky going on, but as noted, it works perfectly on my machine with iTerm assigned as the default application for shell scripts.

 

Could you do a Get Info on a shell script and check which application is assigned as the default for that filetype?

Link to comment

> Could you do a Get Info on a shell script and check which application is assigned as the default for that filetype?

Can confirm it was using iTerm as default application

 

But you've helped me to reproduce the problem purely in iTerm now, taking Alfred out of the equation completely

 

When I invoke my script from a command prompt in iTerm (the script which just creates an SSH session), and then CMD+W that terminal tab, it always leaves a zombie process

 

When I was testing previously (in my first post), I was actually bypassing the script and just typing 'ssh root@nelson'.

It falsely gave the impression Alfred was somehow involved 

 

Thanks a lot for the help, I guess I'll be off to the ITerm support forums now :-)

Edited by paulc
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...