sawyl: (Default)
[personal profile] sawyl
Most of the files I copy around tend to be system specific, so it usually makes more sense to copy them to a local directory like /tmp/$LOGNAME rather than a global directory like $HOME. So far, so good. But what happens if /tmp/$LOGNAME doesn't exist and I attempt to scp to it? A big ugly mess with a potentially sensitive file sitting around on /tmp for anyone to find, not to mention problems with whatever I've got set up in my profile to automatically create my jtmpdir.

My solution to problem? A bit of bash magic. It turns out that bash sources the contents of .bashrc for both interactive non-login shells and non-interactive remote shells, e.g. ssh and scp. This make it possible to customise the remote environment thus:

  stty > /dev/null 2>&1
  if [ $? != 0 ]
  then
    # Remote shell customisation
    export ENVIRONMENT=REMOTE
    export TMPDIR=/tmp/$LOGNAME
    [ ! -d $TMPDIR ] && mkdir -m 0700 $TMPDIR
  else
    # Interactive shell customisation
    [ -f ~/.bash_profile ] && source ~/.bash_profile
  fi

The nice thing about this is that the mkdir is pretty much guaranteed to run before the start of the copy part of an scp session making the whole remote directory existence thing a don't care situation.

Date: 2006-05-16 01:47 pm (UTC)
From: [identity profile] drspleen.livejournal.com
ooo, aren't we just mister fancy pants.

Date: 2006-05-16 08:16 pm (UTC)
From: [identity profile] sawyl.livejournal.com
You're not wrong. I think my shell init scripts weigh in at around three or four thousands lines, excluding all the autocomplete functions. No wonder it often takes me over a minute to log in to one of the busy systems at work...

Profile

sawyl: (Default)
sawyl

August 2018

S M T W T F S
   123 4
5 6 7 8910 11
12131415161718
192021222324 25
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 4th, 2026 09:10 pm
Powered by Dreamwidth Studios