Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute commands on session exit #105

Open
spothound opened this issue Nov 14, 2020 · 4 comments
Open

Execute commands on session exit #105

spothound opened this issue Nov 14, 2020 · 4 comments

Comments

@spothound
Copy link

Hello there!

I would like to know if there is a way to configure certain script to be run when an xxh session end, for example, to delete the hermetic environment or to retrieve some files generated during the seesion (log files or something like this) using sftp or whatever.

If it is not possible, would you consider including such feature? I would be glad to work on this and open a Pull Request : )

(I think it may be interesting to support a different kind of plugin that allow running code at the end of the session instead of at the beginning)

Best regards.

For community:
⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@anki-code
Copy link
Member

anki-code commented Nov 14, 2020

Hi @grg121!

There are three ways:

  1. Using +hhr option (:exclamation: be careful if you use not hermetic environment):

    xxh --help | grep home-remove -A1 
    #  +hhr, ++host-xxh-home-remove
    #                        Remove xxh home on host after disconnect.
  2. Fork any xxh shell and add the commands after the last line of the entrypoint in your personal version of xxh-shell.

  3. Implement this as a feature in plugins ecosystem. It looks easy. We have support of prerun.sh (the real life example in xxh-plugin-prerun-dotfiles) and you can just copy and paste this block of code to the end of entrypoint and rename *prerun.sh to *postrun.sh. If you have lack of time to implement and test it for all xxh-shells you can do it only for your lovely xxh shell and community replicate this solution if needed. PRs are welcome!

@spothound
Copy link
Author

Thank you for your answer @anki-code I'll check the third solution as it seems to me the most correct one and I would be glad to test it and open a PR soon.

Best regards,

@spothound
Copy link
Author

spothound commented Nov 15, 2020

Hello @anki-code,

I've checked your answer I've concluded that:

  1. I could use ++host-xxh-home-remove to remove the hermetic home directory at the end of the session, that's awesome and would prevent me from making any plugin for that.

  2. Nevertheless, for my project, I require to generate some syslog logs on the remote and local machines and I would like to have a xxh plugin that could retrieve these logs from the remote endpoint at the end of the session and merge them with the local ones... and I think I couldn't do this easily with a postrun script like the one you described. Because I won't be able to rsync with the local machine from the remote one (Won't know any credentials).

So, I've made this change on my xxh fork, to add some python code at the end of the xxh session (I'm sourcing the script in order to keep all the previously defined variables and functions and do not lost password or other credentials)

https://github.com/grg121/xxh/pull/1/files

I would like to know what would you think about this change, and If you would consider adding this to the project.

I understand that maybe what I need is something too specific and it doesn't make any sense to add this code to the project just for me but I've been thinking in possibles usages for it and maybe it would be an interesting option for future users).

Best regards and thanks for read!

@anki-code
Copy link
Member

Got it! I suggest to leave this approach in your fork until you finish your work around the complex syslog solution you're working on. After time probably you'll want to change the logic or will have more info.

It's great that you have resolved your current needs using a fork!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants