8

I have a server which when it starts, a line in .bashrc executes the following command /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 2 different user accounts for different .bashrc's.

Is there another angle to approach this from?

  • 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 '13 at 19:27
4

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
  • worked like a charm and all answers here taught me a lot. Much appreciated! – ljs.dev Nov 3 '13 at 20:10
12

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"
  • have you tried your ways? (esp. #2)? – umläute Nov 3 '13 at 19:19
  • 1
    The 2nd method just hangs for me. – slm Nov 3 '13 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. – Dan Garthwaite Nov 6 '13 at 17:49
  • both just hang for me – Aditya Mittal Jan 7 '17 at 23:41
  • @AdityaMittal Both will appear to hang if you are invoking an interactive session because there is no PS1 prompt. Try typing 'ls /' – Dan Garthwaite Jan 9 '17 at 15:35
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.

  • ok, great. In this instance, I may have multiple shells running the watch command, but I like the solution. – ljs.dev Nov 3 '13 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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