How to execute remote shell commands via SSH?
I would like to automatically execute a command on the remote shell when I login through SSH to the server. The main problem is that due to some technical issues on the remote server (which it not going to be solved in near future), my home directory does get mounted automatically when I login. However it's possible to mount the home directory throught some manual commands. So I would like to have these commands executed automatically.
I know that it's possible to invoke SSH with a command option, like ssh user@server COMMAND , however this closes the connection after executing the COMMAND, while I need an interactive shell.
So is it (at all) possible to use SSH to login to a server and automatically execute some commands without losing the connection while not having access to .bashrc etc?
How to execute remote shell commands via SSH
i noticed someone had a similar question and i did not see a conclusion. I am new to Linux and writing scripts. i need to open an SSH connection to a remote server and execute some commands. It can be any command. I would like the connection to stay open and not close. In my script below i tried the Top command. I can open the connection but any command fails. I got the script from Nixcraft. What am i missing?
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set username [lrange $argv 2 2]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh email@example.com
# Look for passwod prompt
# Send password aka $password
send -- "MyPassWord\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
top -b -n 1 | head -n 8