Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am curious, frequently I would like to transfer all of my shell settings (dotfiles) over to a remote session just during my session and then have them reversed when I logout. Even better would be to only make these active on this session so that anyone else who logs in will also be able to have the default or their own custom settings for the shell.

Is there a way to presently do this or would it require a custom solution of me writing this functionality myself? I'm not presently seeing any real options to accomplish this.

share|improve this question

3 Answers 3

You don't have to write much (just a shell script). The tools are already there. Use them to export only what you need to avoid the burden of fixing others' shell functions.

(set; alias) |
ssh -l root 10.3.0.8 'mkdir ~/tmp 2>/dev/null; cat > ~/tmp/.import'

This is not failsafe, so you should try the output until you think it works properly.

(set; alias) > ~/tmp/import
bash -n tmp/import

tmp/import: line 6085: syntax error near unexpected token `('
tmp/import: line 6085: `        !(?(*/)python*([0-9.])|-?))'

This is less of a problem with only environment variables because a parseable format is easy to enforce:

env | sed -Ee "
      s/'/\\\\'/g;
      s/=(.*)/='\1'/
      " > tmp/export.vars-only

And exporting only your functions can be done like so.

declare -f `grep  ^function ~/.functions | awk '{print $2}'`

If you use the moo() { true;} syntax to declare them or some variation thereof you can try grep -Eoe '^\w+' ~/.functions

share|improve this answer

I'm afraid you're going to have to write something custom....something along the lines of a simple cp command for the directories and files involved.

share|improve this answer

Depending on exactly what you need, there are several solutions.

  1. If you have control of the openssh server configuration, you can set up AcceptENV on the server, and then SendENV in client will send over specific environmental variables.

  2. If that is not enough, and you use key auth, you can use authorized_keys entries to run specific commands such as loading a settings files that you have transferred already.

  3. If neither of these work for you, you will just have to wrap your script/command with a wrapper that sets up your environment.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.