4

I want to be able to set a custom prompt (to help with automating jobs, the prompt should be something I can reliably detect). I found I am able to set the prompt remotely, like this:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase 
~ # echo $PS1
\w \$
~ # PS1='Setting a custom prompt \w \$ '
Setting a custom prompt ~ # exit
Connection to 192.168.1.124 closed.

Is there a way to do it in one shot in the first place, by using a different ssh command? The suggestion I tried in the answer of a related question didn't work for me:

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase -t "PS1='Sending a custom prompt \w \$ '; exec sh"
~ # set
HOME='/var/tmp'
IFS='   
'
LOGNAME='guest'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='1039'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD=''
SHELL='/bin/sh'
TERM='xterm'
USER='guest'
fixer1234
  • 27,064
  • 61
  • 75
  • 116
wim
  • 3,087
  • 5
  • 42
  • 57
  • Not even if you add `export ` just in front of `PS1=`? – Eroen Mar 13 '12 at 05:56
  • ah, your suggestion worked :) if you add it as an answer, i can accept it tomorrow. – wim Mar 13 '12 at 06:03
  • I just have it changed in my .bashrc file so I know what I'm on at a glance by what info is shown. – Rob Mar 13 '12 at 06:18
  • @Rob do you mean the .bashrc file on the remote machine? if so, that is not an option for me – wim Mar 13 '12 at 06:36

2 Answers2

7
$ ssh ::1 -t "export PS1='Sending a custom prompt \w \$ '; exec sh"
Password: 
Sending a custom prompt ~ $ exit
Connection to ::1 closed.
Eroen
  • 6,383
  • 1
  • 17
  • 25
0

Did you consider editing the .bashrc file on the remote host?

A simple:

export PS1='Setting a custom prompt \w \$ '

at the end of ~/.bashrc on the remote host will make sure the prompt is changed each time you log in. It will obviously affect any other users of the account too.

Chris Moore
  • 137
  • 1
  • 3
  • 8
  • 1
    Thanks, I considered it - but I need to do it on hundreds of dumb boxes, so it is preferably to be able to send it on the fly rather than set it up on each one. – wim Mar 13 '12 at 06:48