LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Screen Command with Bash Scripting (https://www.linuxquestions.org/questions/linux-software-2/screen-command-with-bash-scripting-655749/)

inthecrossfire 07-14-2008 06:09 PM

Screen Command with Bash Scripting
 
I'm trying to create a BASH script that uses screen to connect to a remote system and run a few commands. However there aren't any instances of screen running when the script is run. Is there a way to start an instance of screen in the background so that I can then send commands to it using 'screen -X'? The current problem is that if I invoke screen it just starts the terminal in the foreground and BASH loses control.

Thanks.

rlhartmann 07-14-2008 08:56 PM

To run any command in the background,
add an & to the end of the command.

inthecrossfire 07-14-2008 11:23 PM

For whatever reason, screen decides not to go to the background when run as "screen &". Any ideas?

jmfv 07-15-2008 08:31 AM

Hello.Try

Code:

screen -d -m
Cheers

skog 07-15-2008 10:05 AM

+1 jmfv

some more screen that might help

$: screen -d -m links google.com

$: screen -d -m links slackware.com

$: screen -r
There are several suitable screens on:
31426..{MY HOST NAME} (Detached)
31434..{MY HOST NAME} (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

$: screen -r {31426}

the {31426} is the first num from screen -r output in previous command. This will bring up the `links google.com` page.

So now you should have your links up to google.com on your screen. You can surf around and whatever, or if its a script you could be watching the output.

To detach this screen and go back to your normal console hit <CTRL>+<A> and then <CTRL>+<D>. Now the screen to links google.com will be back in the background.

There are lots of other <CTRL>+<D> and then <CTRL>+<KEY> commands check out the man file for more.

inthecrossfire 07-15-2008 01:18 PM

Awesome. Thanks very much.


All times are GMT -5. The time now is 12:00 AM.