LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-26-2004, 04:34 PM   #1
SaxyWeed
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Rep: Reputation: 0
determining if shell is local connection or remote


How do I do it?

I want to make a prompt, among other things, that can tell if I'm on a local connection or connecting from a remote host.. First I was thinking about checking pts vs tty but that doesn't cut it. Maybe something about checking hosts in bashrc then setting a variable and the prompt. But how would I go about checking hosts like that?

Thanks,
Matt
 
Old 01-26-2004, 04:36 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Welcome to LQ.

If it is an ssh connection then you should have the variables:
SSH_CONNECTION
SSH_CLIENT
 
Old 01-26-2004, 04:40 PM   #3
SaxyWeed
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Awesone.. Thanks for the quick reply.. Looks like I can test if $SSH_CONNECTION exists first then test it the first and third words of $SSH_CONNECTION are the same and that will give me local connection

Thanks agian,
matt
 
Old 01-26-2004, 11:17 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
\h or \H will print out the host name.

If I change PS1 by the command: export PS1="\h@\H\$" I get the prompt:
jschiwal @ matrix.jesnet$

My default PS1 is set to "[\u@\h \W]\$". The host entry tells me where I'm logged in to.

The bash shell uses different startup files for a log-in session.
/etc/profile, then ~/.bash_profile, then ~/bash_login then ~/.profile. When logging out, bash reads and executes the commands in the file ~/.bash_logout.

When the shell is not a login session, ~/.bashrc is executed instead. The .bashrc file probably contains a test for /etc/profile, and executes it if it exists. But you could change this behaviour if you wanted to.

This is a little bit different from what you asked, but might give you an Idea which startup file should change PS1.

If you type: info bash and then PS1, you can find a listing of all of the prompt codes.

I think there is also a BASH PROMPT HowTo around with advice on what you might want in your prompt.

Last edited by jschiwal; 01-26-2004 at 11:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setting-up an xserver connection with remote host through local firewall. qanopus Linux - Security 5 02-02-2006 10:11 AM
mounting local hard drive in a remote shell (SSH) noir911 Linux - General 1 06-24-2005 05:55 AM
determining shell abk4523 Linux - Newbie 2 06-09-2005 08:28 AM
Determining current shell subu_s Programming 11 01-04-2005 07:10 AM
Determining which shell is in use chakkerz Linux - Newbie 2 11-15-2004 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration