Hacker News new | past | comments | ask | show | jobs | submit login

For automatic cleanup, you can try bash's trap command. Set up a cleanup trap when you create the file.

In .ssh/rc:

  if [ -n "$DOMAIN" ]; then
    # ... create socket & report to user

    clean_socket(){ rm /tmp/test.dev.tld.socket; }
    trap clean_socket EXIT INT HUP;

  fi



Oooh, I hadn't considered HUP. I tried to use a cleanup script with a bash trap on I think INT and KILL but it didn't seem to work correctly. I had also never tried to use a trap command, though, so there was a good chance I was doing it wrong lol. I'll give this a shot!


Ohh so I just gave this a shot and I think that the trap runs when `.ssh/rc` exits, which is immediately when my bash prompt shows up. But if I want to make it non-interactive (in a really hacky way) then I can have my .ssh/rc file just infinitely sleep if domain is defined. Then I killed the ssh connection via a `kill` command on the client side and it appropriately cleaned up the socket file in tmp.

I combined this infinite loop in ssh rc and a -T and a simple command "echo hello" in my client function and now it prints out the link to visit, hangs infinitely until I close it or it gets closed, and cleans itself up.

This just took the level of hackishness to new heights and I love it.


Using a trap didn't work?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: