Change putty title name

Hello all,

I have a not so unix question for you guys(or maybe it is). I use PUTTY to login to serverA (my putty title shows as serverA.domainname.com)

Now from ServerA i do ssh user@ServerB (i have ssh public private key setup)...

now my question is when i do ssh and logon to serverB...my putty title still shows as serverA.domainname.com....is there anyway to "AUTOMATICALLY" change that to ServerB.domainname.com without going into putty menu and stuff ???

---------- Post updated at 12:15 PM ---------- Previous update was at 12:11 PM ----------

i know i can use something like below to change the title..but how can it be down automatically ?? without change profile and stuff on each server i do ssh to

printf "\033]0;asdf\007"

Put it into your profile files on the relevant servers, possibly into your PS1(prompt) variable. How to do so depends on the shells involved.

Thanks for the info...but i do not want to put in this all the server, we have well over 600+ servers...it would be painfull to do that....anyway to do this inside ServerA and when i ssh to serverB or serverC....it chanages automatically ?

Perhaps something like

ssh username@host export PS1="whatever" exec /bin/sh
$ ssh oracle@serverB export PS1="whatever" exec /bin/sh
ksh: /bin/sh: is not an identifier
$
$
$ which sh
/usr/bin/sh
$
$
$ ssh oracle@serverB export PS1="whatever" exec /usr/bin/sh
ksh: /usr/bin/sh: is not an identifier
$

You can replace ssh with your own function. So when you type ssh, you set title, execute real ssh, then set the title back. Try this in profile on ServerA:

ssh() {
        local args=( "$@" )

        #try find out destination
        while [[ $1 = -* ]]; do shift; done

        printf '\033]0;%s\007' "$1"
        command ssh "${args[@]}"
        printf '\033]0;%s\007' "$USER@$HOSTNAME"
}

i saved your funtion in a file and executed it that way...but complaints about this error...

$ ./test.sh
./test.sh: syntax error at line 2 : `(' unexpected
$

Remove the /bin/ from sh and hope sh's in the path, I guess.

And that kind of function only works in a few certain shells. What's your shell?

Sorry I just now saw you use ksh. I have mksh and it allows local but you must split that to two lines. I am not well read on ksh.

local args
args=( "$@" )

edit: that function is by no means a complete wrapper. many ssh options take arguments (i.e. ssh -p 123 user@host ). if you never use options, the function can be made a lot simpler (always use $1 as title), otherwise it can be made a lot lengthier to shift through them.

Thank you for your help...but seems like still giving my same or similar issue...

$ cat test.sh
ssh() {
local args
args=( "$@" )
        #try find out destination
        while [[ $1 = -* ]]; do shift; done

        printf '\033]0;%s\007' "$1"
        command ssh "${args[@]}"
        printf '\033]0;%s\007' "$USER@$HOSTNAME"
}
$
$
$ ./test.sh
./test.sh: syntax error at line 3 : `(' unexpected
$
$

Try

function ssh
{
...
}

Same thing...

Still no ksh wizard? is ksh88 or ksh93? try

set -A args "$@"

Thanks, atleast past though one stage..or the main one...but when i exit out..the title remains the same as ServerB....and i get below....

servername:/home/oracle> exit
logout
Connection to servername closed.
ssh[8]: HOSTNAME: parameter not set
$

then use `hostname` instead or just put serverA in there ...

Thanks...its already using hostname in the code...

ssh() 
{
set -A args "$@"
        #try find out destination
        while [[ $1 = -* ]]; do shift; done

        printf '\033]0;%s\007' "$1"
        command ssh "${args[@]}"
        printf '\033]0;%s\007' "$USER@$HOSTNAME"
}

`hostname` differs from $HOSTNAME

THANK YOU GUYS...You are awesome...

Hello all again,

I know this is an old post, but wanted to bring it up. This works perfectly fine for putty....i have something like below that change my putty title when i do
ssh username@server name....

# SSH Wrapper
ssh()
{
set -A args "$@"
    #try find out destination
        while [[ $1 = -* ]]; do shift; done

        printf '\033]0;%s\007' "$1"
        command ssh "${args[@]}"
        printf '\033]0;%s\007' "`whoami`@`hostname`"
}

But now i have a question with regards to another tool...Putty connection manager or any other Tabbed style putty tool...the title dose not seems to change...is there anything special i need to do to get that changed for putty connection manager??

Anything on the above ?