Search code examples
linuxbashgnomegnome-terminal

Gnome-Terminal Linux Script


I am trying to write a basic write for Linux that opens a terminal window, sends a command, and then sends a character such as "Y" or "N". Also, after a fixed period of time, stop the process.

So far I can get the window and command running using:

gnome-terminal -e "command"

Anyone know how I can send a character like "Y" after that command executes in the new terminal window as well as stop the process in that window after a fixed period of time?


Solution

  • Create your executable file which allow to send a character into new window terminal.

    example yourexecutable.sh (refer to @ændrük example):

    #!/usr/bin/expect -f
    
    # Get a Bash shell
    spawn -noecho bash
    
    # Wait for a prompt
    expect "$ "
    
    # Type something
    send "my text to be posted"
    
    # Hand over control to the user
    interact
    
    exit
    

    then by using timeout command run this command

    gnome-terminal -e "timeout 10 ~/yourexecutable.sh"