LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-25-2008, 03:42 PM   #1
Vanyel
Member
 
Registered: Jul 2007
Location: NY, NY
Distribution: RHEL, CentOS, MacOS X
Posts: 158

Rep: Reputation: 29
Getting a command to run on ssh/cli login ONLY


I've got a FC8 machine that I sit and use at the console a lot, but also access remotely via ssh. Also sometimes I ssh in as another account and then su to my own account.

There's a particular command I'd like to run ONLY if I ssh into the machine as myself, or su to myself, but NOT if I sit down and have a graphical session at the console.

I'm not sure where I'd put it so it will run only on non-GUI (ssh) login or via su.

Can anybody give me an answer?

- Van
 
Old 02-25-2008, 04:56 PM   #2
chadl
Member
 
Registered: Sep 2005
Location: US
Distribution: Gentoo AMD64 Testing
Posts: 129

Rep: Reputation: 16
You can detect if you are connecting via SSH by looking for the SSH_CLIENT environmental variable in your bash startup scripts.

Checking for the display environmental variable might work for telling a GUI/Console login apart, although I am not sure of that.

Running env will list all variables that are currently set, so you can compare the different login types and find variables that can tell them apart.
 
1 members found this post helpful.
Old 02-26-2008, 11:28 AM   #3
Vanyel
Member
 
Registered: Jul 2007
Location: NY, NY
Distribution: RHEL, CentOS, MacOS X
Posts: 158

Original Poster
Rep: Reputation: 29
Yes yes YES!!!

This is just what I was looking for. I never have to explicitly deal with my environment variables so I'd never have thought of that.

After running 'env' I realized GDMSESSION will only exist if I have logged in at the console. If I ssh in as myself or am logged in as another account (even in the GUI), then 'su - van' to myself, GDMSESSION will be undefined. That's what I need to know!

Thank you.

- Van
 
Old 03-02-2008, 06:44 PM   #4
gatoatigrado
LQ Newbie
 
Registered: Aug 2007
Location: Berkeley, CA
Posts: 4

Rep: Reputation: 1
another way is to do
ssh -t <machine name> "command; <your shell, e.g. bash>"
the -t forces tty (roughly i.e. text terminal) which allows bash to work

I think this is more flexible b/c you don't have to have different local users to run different commands, and the server doesn't have to know about those users.
 
1 members found this post helpful.
Old 03-03-2008, 09:38 AM   #5
Vanyel
Member
 
Registered: Jul 2007
Location: NY, NY
Distribution: RHEL, CentOS, MacOS X
Posts: 158

Original Poster
Rep: Reputation: 29
Not quite better for my uses, but I see other scenarios where I could use it. Another eye-opener. 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run command on ssh inactivity? lil_drummaboy Linux - Security 6 12-15-2020 11:27 AM
After login attempts, can a script be run from ssh daemon ? frenchn00b Linux - Software 2 01-02-2008 11:41 PM
[SSH]Which login scripts are run? jamesstanley Linux - Server 3 11-17-2007 06:24 AM
ssh login error - unknown command atom Linux - Software 3 05-12-2004 04:37 PM
run command at boot/login? apberzerk Linux - General 1 09-22-2003 10:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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