13

I have a server which executes this line in .bashrc when it starts: /bin/watch ~/checker.bash. Which, as expected, watches that command upon server start.

I also have a client which logs into that machine, but I do not want the client's sessions to execute the same command from the .bashrc.

I have looked at AcceptEnv for passing env vars, though it requires configuration of the server, which I want to avoid.

I also don't want to have two different user accounts for different .bashrcs.

Is there another angle to approach this from?

1
  • why don't you want two different accounts? all "clients" (which seem to be an unrelated 3rd parties) should be isolated (also from yourself)
    – umläute
    Nov 3, 2013 at 19:27

3 Answers 3

22

Two ways:

Don't use bash for this session, try dash (or /bin/sh):

ssh 127.0.0.1 /bin/dash

Use bash with command options to disable processing startup files:

ssh 127.0.0.1 "bash --noprofile --norc"
6
  • 1
    The 2nd method just hangs for me.
    – slm
    Nov 3, 2013 at 20:28
  • 5
    The second method works perfectly for me. You don't see a prompt since PS1 isn't set, which is a side effect of performing as requested. Nov 6, 2013 at 17:49
  • both just hang for me Jan 7, 2017 at 23:41
  • 1
    @AdityaMittal Both will appear to hang if you are invoking an interactive session because there is no PS1 prompt. Try typing 'ls /' Jan 9, 2017 at 15:35
  • 1
    this doesnt work for me, because the .bashrc needs to allow it first, and if it has something that runs first that is kicking you off, then you never get past that point. Aug 25, 2018 at 2:55
7

you could activate parts of your .bashrc only if it is not invoked via ssh.

e.g. something like:

# within an SSH-session, ${SSH_TTY} will be set
if [ "x${SSH_TTY}" = "x" ]; then
  /bin/watch ~/checker.bash
fi
0
2

You can substitute the line /bin/watch .... with

 if ps ax | grep /bin/watch | grep -v grep  > /dev/null 2>&1
 then
    echo "Nothing to do"
 else
    /bin/watch ~/checker.bash
 fi

or some such thing.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .