diff --git a/launcher/et b/launcher/et index 543b84508..63daec5b4 100755 --- a/launcher/et +++ b/launcher/et @@ -7,6 +7,7 @@ SSH_COMMAND="" TMP_DIR=${TMPDIR:-${TMP:-${TEMP:-/tmp}}} LOG_DIR=$TMP_DIR VERBOSITY="" +INITIAL_COMMAND="" for i in "$@" do @@ -31,6 +32,10 @@ do VERBOSITY="--v=9" shift ;; + -c=*|--command=*) + INITIAL_COMMAND="${i#*=}" + shift + ;; -h|--help) printf "et (options) [user@]hostname[:port] @@ -41,6 +46,7 @@ Options: -u Username to connect to ssh & ET -l Directory where log files will go -v verbose log files +-c Initial command to execute upon connecting " exit 0 ;; @@ -110,5 +116,5 @@ else echo "${PASSKEY}" > "${TMPFILE}" PASSKEY="" SSH_OUTPUT="" - $CLIENT_BINARY --idpasskeyfile="$TMPFILE" $VERBOSITY --host="$HOSTNAME" --port="$PORT" --log_dir="$LOG_DIR" 2> /tmp/etclient_err + $CLIENT_BINARY --idpasskeyfile="$TMPFILE" $VERBOSITY --host="$HOSTNAME" --port="$PORT" --log_dir="$LOG_DIR" --command="$INITIAL_COMMAND" 2> /tmp/etclient_err fi diff --git a/terminal/TerminalClient.cpp b/terminal/TerminalClient.cpp index 14ac3f625..360062ea6 100644 --- a/terminal/TerminalClient.cpp +++ b/terminal/TerminalClient.cpp @@ -29,6 +29,7 @@ DEFINE_int32(port, 2022, "port to connect on"); DEFINE_string(id, "", "Unique ID assigned to this session"); DEFINE_string(passkey, "", "Passkey to encrypt/decrypt packets"); DEFINE_string(idpasskeyfile, "", "File containing client ID and key to encrypt/decrypt packets"); +DEFINE_string(command, "", "Command to run immediately after connecting"); shared_ptr createClient() { string id = FLAGS_id; @@ -158,6 +159,17 @@ int main(int argc, char** argv) { time_t keepaliveTime = time(NULL) + 5; bool waitingOnKeepalive = false; + if (FLAGS_command.length()) { + LOG(INFO) << "Got command: " << FLAGS_command << endl; + et::TerminalBuffer tb; + tb.set_buffer(FLAGS_command + "\n"); + + char c = et::PacketType::TERMINAL_BUFFER; + string headerString(1, c); + globalClient->writeMessage(headerString); + globalClient->writeProto(tb); + } + while (run && !globalClient->isShuttingDown()) { // Data structures needed for select() and // non-blocking I/O.