LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-14-2006, 09:58 AM   #1
pypieuvre
LQ Newbie
 
Registered: Feb 2006
Location: Paris, France
Distribution: Ubuntu Breezy, Red Hat enterprise linux 3
Posts: 8

Rep: Reputation: 0
ssh : remote command execution doesn't work for modifying env variables


Hello,
I m trying to open an ssh connection on a server and immediatly execute a command after bash login.
I set up the rsa authentication to avoid interactive passwords issues.

I'd like to customize the prompt of the shell on the server, WITHOUT modifying anything on it (specially .bashrc or .bash_profile)

I tried
Code:
$> ssh mylogin@myhost "export PS1=\"my prompt\";bash --login"
It works as long as no personal customization is done on targeted account .bashrc : in that case the variable is overwritten ....

Code:
$> ssh mylogin@myhost "bash --login; export PS1=\"my prompt\""
doesn't work at all.

Code:
$> export PS1='my prompt' | ssh mylogin@myhost
doesnt give me any prompt at all

Code:
$> ssh -t ssh mylogin@myhost <<EOF export PS1=my prompt
> EOF
neither


Don't know what to do ... do you have any idea ?
PS: Sorry for my english ...
 
Old 02-14-2006, 05:00 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
What I'd do is create a shell file with your temp alterations and source it befoe executing any other cmds:

ssh mylogin@myhost
old_prompt>. temp_env.sh
new_prompt>


That's a dot followed by a space followed by shell_file name
 
Old 02-15-2006, 04:57 AM   #3
pypieuvre
LQ Newbie
 
Registered: Feb 2006
Location: Paris, France
Distribution: Ubuntu Breezy, Red Hat enterprise linux 3
Posts: 8

Original Poster
Rep: Reputation: 0
The problem is that I want to do it automatically and without modifying the server's configuration (no script on the server) ...
 
Old 02-15-2006, 11:29 AM   #4
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
try this:

Code:
ssh mylogin@myhost "export PS1=\"my prompt\";bash --login --norc"
from the bash man page:

Code:
--norc Do  not  read  and  execute  the system wide initialization file
              /etc/bash.bashrc and the personal initialization file  ~/.bashrc
              if  the  shell  is interactive.  This option is on by default if
              the shell is invoked as sh.
 
Old 02-15-2006, 12:36 PM   #5
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Yes... bash --login (without --norc) will always read in configuration files. Specifying the export afterward will set the environment variable when bash EXITS.
 
Old 02-15-2006, 04:54 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Well, my suggestion would only temporarily alter the env for that run of that ssh call; ie when the process exits, the env goes away and in any case no other process will be affected unless they source the script also.
Normal programming practice.
 
Old 02-16-2006, 02:57 AM   #7
pypieuvre
LQ Newbie
 
Registered: Feb 2006
Location: Paris, France
Distribution: Ubuntu Breezy, Red Hat enterprise linux 3
Posts: 8

Original Poster
Rep: Reputation: 0
Good points, thanks for the attention guys ;-)

Crism01 I agree with you regarding the way to think about the problem, It's exactly what I'm trying to do, but again your script has to be stored on the server side (no ?), what I'd like to avoid ... and to be run automatically after bash launch.

German , It could be a solution but I don't want to prevent the environmnent to be customized except for specific variables. With your solution the account aliases and variables will be skiped ...
 
Old 02-22-2006, 03:24 AM   #8
pypieuvre
LQ Newbie
 
Registered: Feb 2006
Location: Paris, France
Distribution: Ubuntu Breezy, Red Hat enterprise linux 3
Posts: 8

Original Poster
Rep: Reputation: 0
No more ideas ?
 
Old 02-23-2006, 10:23 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
I think we need more info on eactly WHAT you are trying to do and WHY....
After all, if you are allowed to login and run stuff on the remote box, you are allowed to add scripts to it... or maybe just manually type in any changes you want???
 
Old 02-24-2006, 09:35 AM   #10
pypieuvre
LQ Newbie
 
Registered: Feb 2006
Location: Paris, France
Distribution: Ubuntu Breezy, Red Hat enterprise linux 3
Posts: 8

Original Poster
Rep: Reputation: 0
You're right it could be a solution to deploy some configuration files or scripts on the remote box, the problem is that I ve got about 9 000 of them ...

What I m doing is building a centralized gateway, mandatory to access these thousands of servers (to control and grant accesses). You connect to the central gateway, choose the host you want to connect and then your connection is forwarded to the remote server (exactly like you would do directly).

BUT after opening the connection between the gateway and the remote box I would like to modify an environmnent variable 'on the fly' for the bash session...

Am I a little more clear ? I recognize the issue is a bit particular and difficult to realise.
 
Old 02-24-2006, 09:50 AM   #11
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
what about a grep of the .bashrc and /etc/bashrc files before running bash? something like (totally untested and my regexp knowledge sucks):

Code:
ssh login@myhost "grep [^PS1] ~/.bashrc | sh; bash --login --norc"
edit: on second thought this absolutely wouldn't work because it uses 2 separate instances of bash.

Last edited by german; 02-24-2006 at 10:37 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Adodb Multiple Test Scripts Remote Command Execution ... LXer Syndicated Linux News 0 01-09-2006 06:01 PM
setting env. variables arunsri Slackware 3 03-26-2005 05:49 AM
Remote Command Execution via mobile phone Sammy2ooo Linux - Software 6 06-27-2003 03:42 AM
modifying environment variables zulu1_hl Linux - Newbie 5 02-26-2003 10:33 AM
Open GL env.variables UB_KMA Linux - Newbie 1 08-04-2002 05:41 PM


All times are GMT -5. The time now is 11:34 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration