Forum: Ruby .profile in UNIX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B7f7698eb09ca0849906c023fe6206d3?d=identicon&s=25 Bob Smyph (bobsmyph)
on 2008-12-18 19:42
Does anyone know how to access and use the .profile in UNIX while using
NET::SSH in Ruby?

Thanks for the help
F065301eb65a5d0da8edcb8de9d5e28e?d=identicon&s=25 Tim Greer (Guest)
on 2008-12-18 19:50
(Received via mailing list)
Bob Smyph wrote:

> Does anyone know how to access and use the .profile in UNIX while
> using NET::SSH in Ruby?
>
> Thanks for the help

How to you mean?  By updating it, parsing it from the file itself, or by
using finger, or?
B7f7698eb09ca0849906c023fe6206d3?d=identicon&s=25 Bob Smyph (bobsmyph)
on 2008-12-18 19:56
Tim Greer wrote:
>
> How to you mean?  By updating it, parsing it from the file itself, or by
> using finger, or?

I believe we just need to load it into the session/channel so that we
can use access/use command associated with the .profile

We are trying to run a command through Ruby but it seems that we need
certain environmental properties set (e.g. .profile) in order to do
this. If we log onto the server through Putty this command works just
fine.
F065301eb65a5d0da8edcb8de9d5e28e?d=identicon&s=25 Tim Greer (Guest)
on 2008-12-18 20:00
(Received via mailing list)
Bob Smyph wrote:

> this. If we log onto the server through Putty this command works just
> fine.

Sorry, I got you.  I read the post too quickly and for some reason I
thought you said .plan (I should have known that sounded strange).
Indeed, the .profile is only set to work with shell, in the shell env,
which is why CGI, web server APIs/modules and rails don't read it.  Did
you need to set any environments or did you want to emulate or somehow
use the shell vars naturally (assuming you can trust the
user's .profile)?
B7f7698eb09ca0849906c023fe6206d3?d=identicon&s=25 Bob Smyph (bobsmyph)
on 2008-12-18 20:04
Tim Greer wrote:
>
> Sorry, I got you.  I read the post too quickly and for some reason I
> thought you said .plan (I should have known that sounded strange).
> Indeed, the .profile is only set to work with shell, in the shell env,
> which is why CGI, web server APIs/modules and rails don't read it.  Did
> you need to set any environments or did you want to emulate or somehow
> use the shell vars naturally (assuming you can trust the
> user's .profile)?

If the only way to get this to work is to set the environment/variables
or emulate them somehow in the Ruby script, that is what we will need to
do. Any idea as how to do this?
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 Ara Howard (ahoward)
on 2008-12-19 04:00
(Received via mailing list)
On Dec 18, 2008, at 11:35 AM, Bob Smyph wrote:

> Does anyone know how to access and use the .profile in UNIX while
> using
> NET::SSH in Ruby?
>
> Thanks for the help


you need to invoke a login shell on the remote host, then
your .profile will be sourced.

probably there is some option to specify the remote shell for
Net::SSH, specify something like

   '/bin/bash --login'

alternatively wrap your commands in something that does this for you
like

cfp:~ > cat `which bashenv`
#!/bin/bash --login
exec "$@"


and then invoke commands like 'bashenv something.exe'


a @ http://codeforpeople.com/
63529e6fbb35dde336d471b569b84d87?d=identicon&s=25 Rodrigo Bermejo (rbermejo)
on 2008-12-19 18:55
Bob Smyph wrote:
> Tim Greer wrote:
>>
>> Sorry, I got you.  I read the post too quickly and for some reason I
>> thought you said .plan (I should have known that sounded strange).
>> Indeed, the .profile is only set to work with shell, in the shell env,
>> which is why CGI, web server APIs/modules and rails don't read it.  Did
>> you need to set any environments or did you want to emulate or somehow
>> use the shell vars naturally (assuming you can trust the
>> user's .profile)?
>
> If the only way to get this to work is to set the environment/variables
> or emulate them somehow in the Ruby script, that is what we will need to
> do. Any idea as how to do this?

You can 'source' the .profile in your ssh session doing a:
cmd=". /home/user/.profile"

note the space after the dot.

Regards.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2008-12-19 19:34
(Received via mailing list)
On Dec 19, 2008, at 12:47 PM, Rodrigo Bermejo wrote:
>>> somehow
> cmd=". /home/user/.profile"
>
> note the space after the dot.
>
> Regards.


Read the docs about the intended use and behavior of ~/.profile or
~/.login or ~/.bash_login compared to ~/.bashrc

It's probably in the INVOCATION section of the manual for your shell.


-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
5a601582df3b42b65a5e8353fc9305da?d=identicon&s=25 Gerardo Santana Gómez Garrido (Guest)
on 2008-12-19 19:37
(Received via mailing list)
On Thu, Dec 18, 2008 at 12:48 PM, Bob Smyph
<eric.ramsey@cbc-companies.com> wrote:
> this. If we log onto the server through Putty this command works just
> fine.
> --
> Posted via http://www.ruby-forum.com/.
>
>

If your server is running OpenSSH, you can also use ~/.ssh/environment.

See sshd(8) for details, under the LOGIN PROCESS section:

http://www.openbsd.org/cgi-bin/man.cgi?query=sshd&...
B7f7698eb09ca0849906c023fe6206d3?d=identicon&s=25 Bob Smyph (bobsmyph)
on 2008-12-19 20:31
Thanks to all the help. We took some of your suggessions and some of our
own hacking and got this to work.

thanks
This topic is locked and can not be replied to.