[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: SSH -- Running remote command and NOT Exiting



On Wed, Mar 02, 2005 at 10:08:14PM -0500, Hal Vaughan wrote:
} I know I can use SSH to run a remote command like this:
} 
} ssh newhost command-to-run
} 
} And if I have it set up to use RSA or some other type of authentication,
} it'll connect to the system, log in automatically, and run
} "command-to-run", then log out.
} 
} But I can't find anything in the man page (or on Google, but there's a
} high noise-to-signal ratio, including many copies of the man page) where
} I can tell ssh to run a command on login and NOT exit.  What can I do to
} make ssh login, run a command, then stay logged in, waiting for another
} command?

This is not ssh's problem. Consider the following script:

#!/bin/sh

if test $# -lt 2
then
	echo "Usage: $0 <shell> <command> [arguments to command...]" >&2
	exit 1
fi

SHELL="$1"
shift
eval "$@"
exec "$SHELL"

------------------------------

Suppose you save this to your bin directory on the remote machice as
shellexec, and suppose you use bash as your login shell. Also, suppose
(just for the sake of argument) that the command you want to run is echo
foo. You'd run the following command from the local machine:

ssh -t user@remotehost shellexec bash echo foo

Note that the -t is necessary to have an interactive session even though a
command is being run. Also note that since the arguments to shellexec will
go through at least two shell expansions (one local and at least one
remote), you will have to be very careful about quotes.

That said, I can think of absolutely no good reason to want to do what you
are asking. What are you actually trying to accomplish?

} Thanks!
} Hal
--Greg



Reply to: