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.

With some help from people on here, I was able to set a custom prompt in an ssh session (thanks!). Now I need to do the same in telnet, but I'm not sure of what syntax I could use for that.

Basically the telnet prompt is just a > character, I need to modify it to something I can more reliably detect in automation jobs. Hope this makes sense.

From inside telnet, trying to escape that command with a bang like !PS1=spam and !PS2=eggs did not change it.

wim@wim-acer:~$ ssh guest@192.168.1.124 -i ~/.ssh/guest_nopassphrase -t "export PS1='Sending a custom prompt \w \$ '; exec sh"
Sending a custom prompt ~ $ set
HOME='/var/tmp'
IFS='   
'
LOGNAME='guest'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='1128'
PS1='Sending a custom prompt \w $ '
PS2='> '
PS4='+ '
PWD=''
SHELL='/bin/sh'
TERM='xterm'
USER='guest'
Sending a custom prompt ~ $ telnet localhost <snip>

Entering character mode
Escape character is '^]'.

> !set
CONSOLE='/dev/ttyp0'
HOME='/var/tmp'
IFS='   
'
LOGNAME='root'
PATH='/sbin:/bin:/usr/sbin:/usr/bin'
PPID='546'
PREVLEVEL='N'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD='/var/tmp'
RESPAWN_COUNT='1'
RESPAWN_LAST='0'
RESPAWN_MAX='5'
RESPAWN_TIME='5'
ROOTDEV='/dev/sla1'
RUNLEVEL='5'
SHELL='/bin/false'
TERM='linux'
USER='root'
> 
> Connection closed by foreign host
Sending a custom prompt ~ $ Connection to 192.168.1.124 closed.
wim@wim-acer:~$ 
share|improve this question
1  
Hmmm... Spam, lovely Spam, wonderful Spam! –  Daniel Beck Mar 13 '12 at 8:22
add comment

2 Answers

The prompt is provided by the command shell, not by network protocols such as SSH or Telnet and their associated services and clients. It does not matter whether you are using telnet, ssh, a serial terminal or a local console.

You can set the prompt in many shells (e.g. bash) by setting environment variables such as PS1 and PS2.

Try

 > PS1="hello : "
 hello : 

UPDATE

Your questions says ...

  $ telnet localhost <snip>
  …
  > !set
  …
  SHELL='/bin/false'
  …
  > Connection closed by foreign host

/bin/false isn't a shell! It is the sort of entry that is used to disable telnet logins. You are not going to get anywhere with this. If you really want to use an insecure protocol like telnet instead of a secure protocol like ssh, you'll have to configure the telnet service to provide you with a proper shell.

share|improve this answer
    
This works in sh, but in telnet I get PS1="hello : ": unknown command –  wim Mar 21 '12 at 5:59
    
@wim: see updated answer. –  RedGrittyBrick Mar 21 '12 at 11:22
    
thanks! the device is a set-top box and i don't have permissions to modify firmware, i'm just trying to automate certain jobs on hundreds of these boxes with pexpect and it would be easier if i could match the prompt reliably –  wim Mar 21 '12 at 13:32
add comment

Like @RedGrittyBrick wrote, the fact that you're using telnet or SSH doesn't matter. What does matter is environment variable forwarding.

What you are, in fact, telling ssh to do is to connect to a TTY, then pass the command export PS1='Sending a custom prompt \w \$ '; exec sh to the default shell.

For telnet, look at environ (see the man page). It uses the telnet ENVIRON protocol to transfer environment variables across the connection, and I imagine you can add the appropriate commands to your ~/.telnetrc if you want to, or just export the appropriate environment variables on a per-session basis.

For a proper way of doing it in SSH, look at the ENVIRONMENT section of the ssh man page. Not sure I see an obvious way of doing it per instance, though.

share|improve this answer
add comment

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.