SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
543 stars 36 forks source link

Execute .profile on login to terminal session (AIX) #215

Closed waltlillyman closed 3 years ago

waltlillyman commented 3 years ago

Is it possible to execute the user's ~/.profile script upon login to a terminal session? I'm on IBM's AIX, and when I SSH into the server via putty, the user's ~/.profile shell script executes as expected. But it doesn't execute when I log in via SSH FS. It's like AIX thinks it's a non-interactive login session, I guess. Thanks for this extension!

SchoofsKelvin commented 3 years ago

Did this only start happening recently (version 1.18.3 to be precise) or do you remember it working properly in the past?

There's actually a good chance it does indeed think that. I use exec instead of shell now for technical reasons. This doesn't inherently create an interactive session. It runs a few commands, the last one being $SHELL which should, according to the manuals for sh and bash, result in the shell being started interactively. I'm not sure if AIX does anything special regarding this. Optionally I could always add -i although I'm not sure how well that would go in case there are terminals that don't support that option.

I was thinking about adding a terminalCommand config option (which defaults to $SHELL) so you can set it to e.g. bash -i. I'll also do some more testing to see if there's a flaw in how I create a shell.

waltlillyman commented 3 years ago

I'm a new SSHFS user, so I have no prior experience, sorry.

At my site, all logins to AIX use the korn shell, so $SHELL=/usr/bin/ksh I found this description of a method to invoke ksh as a login shell: https://unix.stackexchange.com/questions/330949/how-to-make-ksh-act-as-if-it-had-been-invoked-as-a-login-shell-aix "ksh behaves as a login shell if the first character of argument 0 is - (hyphen), i.e.: exec -a -ksh /path/to/ksh [optional arguments] will replace the current shell with an instance of the Korn shell which behaves as a login shell."

terminalCommand sounds like a good idea. Otherwise, I think all that's really missing is to source the user's .profile script. So maybe a feature, like, "Startup command", which I could fill in as, . ~/.profile That's what I do manually, now.

SchoofsKelvin commented 3 years ago

"ksh behaves as a login shell if the first character of argument 0 is - (hyphen)

That's for a login shell, not an interactive shell. Here is a stackoverflow that talks a bit about the difference. The issue here seems to be that you require an interactive shell, but don't get one, although this stackoverflow does mention only ksh login shells execute ~/.profile, while this one mentions it too, although some shells (e.g. bash) might still execute stuff. I tested it, and running bash on my Ubuntu test machine does indeed read .bash again.

I'll check whether replacing $SHELL with $SHELL - or $SHELL -l would be valid for all distros. I'll also be adding terminalCommand, which you can set to ksh -.

jraygauthier commented 3 years ago

See #221 for some example how this is done in the remote ssh extension. Both issues are similar..

SchoofsKelvin commented 3 years ago

As mentioned in #221, I added a Terminal command option to the Settings UI (or terminalCommand in settings.json) where you can customize the command used to launch the shell. Defaults to $SHELL but can be e.g. $SHELL -l instead.

I'm still interested in figuring out whether $SHELL - or $SHELL -l is valid for every distro and (common?) shell type before I make it the default.

waltlillyman commented 3 years ago

I’m on holiday but when I return, I’ll test those combinations on AIX and reply. Thank you very much!

waltlillyman commented 3 years ago

On AIX 7.1, using Korn shell, -l isn't a documented option, and when I use it with your extension's new Terminal command as $SHELL -l, the terminal window opens and disappears quickly. So I'm just living with my workaround of manually invoking my .profile after launching SSH FS. Thank you!

SchoofsKelvin commented 3 years ago

I'm just living with my workaround of manually invoking my .profile after launching SSH FS

If the Korn shell has other arguments to load a profile file, or run a specific commands (e.g. korn -c "echo 12"), you can change the terminal command to something like $SHELL -c "exec .profile; $SHELL" or even exec .profile; $SHELL, or whatever else fits your needs.

On AIX 7.1, using Korn shell, -l isn't a documented option, and when I use it, the terminal window opens and disappears quickly.

This would be a major reason why I don't make $SHELL -l the default.

flyingdutchman commented 3 years ago

If the Korn shell has other arguments to load a profile file, or run a specific commands (e.g. korn -c "echo 12"), you can change the terminal command to something like $SHELL -c "exec .profile; $SHELL" or even exec .profile; $SHELL, or whatever else fits your needs.

I also want my bashrc or my bash_profile to be sourced at boot without specifying it in the "command" of a task but rather in the "terminalCommand" of the configuration to have all my dev env set up.

But I can't seem to make it work. Even using the commands you gave here it is as if they were ignored. But writing it manually in the "command" does work though. Any idea what it could be ?

SchoofsKelvin commented 3 years ago

I also want my bashrc or my bash_profile to be sourced at boot without specifying it in the "command" of a task but rather in the "terminalCommand" of the configuration to have all my dev env set up.

The terminalCommand is purely used for the terminal, but I could add something like a shell option to specify the command used to launch the task's shell.