Forum Moderators: bakedjake

Message Too Old, No Replies

Logged in host IP address?

For use in shell script

         

physics

7:43 pm on Feb 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to write a bash shell function to be used on a remote system that:
- Gets the IP or host name that I'm currently logged into the system from
- sends the specified file from the remote system to said host

If I know the host name I can do it:


function scpme()
{
scp $1 me@my.home.mahcine.hostname.net:./$2
}

But I want it to work regardless of where I'm logged in from, not just the hardcoded my.home.mahcine.hostname.net.

So the simple question is: is there a shell variable like $REMOTE_HOST that stores the IP I'm logged in from?

py9jmas

8:04 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



SSH in to the remote system and have a look at
$SSH_CLIENT
$SSH_CONNECTION
You should be able to do what you want from there.

physics

8:33 pm on Feb 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. Is the user name of me on my home system available also somehow? I.e. if on the remote host I'm me2 and at home I'm me is there a way to get me on the remote host?

py9jmas

9:26 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



A read of the ssh man page revealed:
Additionally, ssh reads $HOME/.ssh/environment, and adds lines of the format ``VARNAME=value'' to the environment if the file exists and if users are allowed to change their environment. For more information, see the PermitUserEnvironment option in sshd_config(5).

which sounded promising - you could pass whatever you liked to the environment on the server. However, PermitUserEnvironment defaults to No, at least on FreeBSD. Nothing else looks much use, I'm afraid.