Skip to content

Commit

Permalink
add -c flag that runs commands on login. Closes #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Gauci committed Jun 16, 2017
1 parent 3ae4281 commit c4cf5eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion launcher/et
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SSH_COMMAND=""
TMP_DIR=${TMPDIR:-${TMP:-${TEMP:-/tmp}}}
LOG_DIR=$TMP_DIR
VERBOSITY=""
INITIAL_COMMAND=""

for i in "$@"
do
Expand All @@ -31,6 +32,10 @@ do
VERBOSITY="--v=9"
shift
;;
-c=*|--command=*)
INITIAL_COMMAND="${i#*=}"
shift
;;
-h|--help)
printf "et (options) [user@]hostname[:port]
Expand All @@ -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
;;
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions terminal/TerminalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientConnection> createClient() {
string id = FLAGS_id;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c4cf5eb

Please sign in to comment.