Reputation: 399
I'm creating files on a Linux server that I'm logged into and I'm adding the ability for the user to download these files from the Linux server on to the connecting computer. I'm writing a scrip and using the scp command to download these files:
scp data.txt user@usraddress:/home/usr
However, I don't want to specify "user@usraddress:/home/usr" to be just my computer. I want whoever is logged onto the linux server to be able do download these files. Is there a way to get the address of the connecting computer? How would I do this?
Forgive me if this seems elementary, I'm very new to scripting.
Upvotes: 1
Views: 2823
Reputation: 193
When you open a remote session in a GNU/Linux machine, the ssh server sets the environment variable SSH_CONNECTION
with some connection information. You can use this variable and the $USER
variable to fill that parameters:
scp data.txt $USER@${SSH_CONNECTION%% *}:/home/$USER
Note that as far as I know you couldn't assume the client home directory is at /home
. As said by chepner, you could omit the destination directory to use the default location, the home directory.
scp data.txt $USER@${SSH_CONNECTION%% *}:
Upvotes: 2