LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-28-2006, 10:10 PM   #1
unreal128
Member
 
Registered: Jun 2003
Distribution: SuSE, Slackware, Gentoo
Posts: 207

Rep: Reputation: 30
Unhappy Detect remote or local connection from shell.


I have a script that runs on a network of systems. There is a feature in the script that allows users to connect to other systems. I want to disallow some features of the script if the user is already calling the script from a remote system (eg. calling script from telnet/ssh/konsole/xterm session.)

Is there a way to check from the shell to see if my session is remote or local? I used to use 'who am i' as a way to discover this but infortunately it doesn't work in X windows. I tried playing around with searching for the parent of $PPID (bash reserved variable) but this can get muddled since they can call any range of apps to connect remotely and I would have to exclusively search for them. I even tried calling up the terminal type attached to the shell via 'tty' but "pts/*" will show as my tty from a local X session or when connected remotely via telnet/ssh/konsole/xterm.

I basically want to...
Code:
 
if [ $detected_type_of_session -eq $true_condition ]; then
   runcodehere
else
   runcodethere
fi
Please help!
 
Old 07-28-2006, 10:33 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Would testing for a value in $DISPLAY be sufficient?

This assumes remote users aren't allowed to forward X displays over ssh. And it assumes local users are logging in to a X session.

Code:
if [[ -z "$DISPLAY" ]] ; then echo 'Aha! Remote user!' ; fi
Just one idea. Probably many ways to do it.
 
Old 07-29-2006, 12:13 PM   #3
unreal128
Member
 
Registered: Jun 2003
Distribution: SuSE, Slackware, Gentoo
Posts: 207

Original Poster
Rep: Reputation: 30
Good idea! I looked at the DISPLAY variable before but failed to realize values of display *:10 and up were remote. If I can't grab by 'who am i', I will defer to this variable. Thanks!
 
  


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
Mandrake 8.2 doesn't detect local printer. Edmond B Linux - Hardware 5 03-16-2006 01:06 AM
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 if shell is local connection or remote SaxyWeed Linux - General 3 01-26-2004 11:17 PM
Remote Mounting? (Mount remote folder on local filesystem) mac_phil Linux - Networking 1 11-15-2003 03:48 PM

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

All times are GMT -5. The time now is 11:05 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