Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to know if there is a way to specify what script to run (on the remote machine) at login. I'm logging into a Debian box with key-pair authentiation (no password needed). The script needed to run will be different, so I don't want to put it into ~/.bashrc, I want to specify it on the command line when I login, something like:

ssh username@ip script_on_remote.sh

share|improve this question

migrated from serverfault.com Apr 22 '13 at 13:15

This question came from our site for professional system and network administrators.

add comment

2 Answers 2

up vote 5 down vote accepted

Your example is pretty much how you'd do it. You can specify the script using it's full path if it's not accessible on the $PATH.

# if scripts on the $PATH
ssh username@ip script_on_remote.sh

# if it's not on the path
ssh username@ip /path/to/my/script_on_remote.sh

# if it's including spaces
ssh username@ip "/path to my/script_on_remote.sh"
share|improve this answer
add comment

Specifying the command on the command line will work. You may have to put in the full path of the command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.