0

I want to execute

expect -c "
    spawn ssh user@10.0.0.0
    expect \"assword:\"
    send \"pass\r\"
    interact "

in a new terminal by doing double click in an .sh script.

I tried

#!/bin/bash

commands () {
    expect -c "
    spawn ssh root@10.0.0.0
    expect \"assword:\"
    send \"pass\r\"
    interact "
    $SHELL # keep the terminal open after the previous commands are executed
}

export -f commands

gnome-terminal -e "bash -c 'commands'"

with no luck. Any ideas?

user1532587
  • 657
  • 8
  • 17

1 Answers1

0
  1. You can use gnome-terminal with the --disable-factory option that does:

    "Do not register with the activation name server, and do not reuse an already running GNOME terminal process"

    It will let the 'commands' environment variable through.

    gnome-terminal typically runs in a server mode. First launch starts a process, next launches send messages to main process to open a new window. So, env vars are set only on the first launch.

  2. You can use a separate script file and pass its file name to bash. Or make it clever: detect inside this script its actual file name and pass it to bash, so it'll call this same script inside the gnome-terminal (but pass a parameter to take a different code path).

  3. You can stuff everything into a variable, but make sure that it expands before the call to the gnome-terminal.

Velkan
  • 3,616