Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-14-2008, 06:09 PM   #1
LQ Newbie
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
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.

Old 07-14-2008, 08:56 PM   #2
Registered: Mar 2008
Posts: 73

Rep: Reputation: 16
To run any command in the background,
add an & to the end of the command.
Old 07-14-2008, 11:23 PM   #3
LQ Newbie
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
For whatever reason, screen decides not to go to the background when run as "screen &". Any ideas?
Old 07-15-2008, 08:31 AM   #4
LQ Newbie
Registered: Nov 2006
Distribution: Debian Stable
Posts: 17

Rep: Reputation: 1

screen -d -m
Old 07-15-2008, 10:05 AM   #5
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
+1 jmfv

some more screen that might help

$: screen -d -m links

$: screen -d -m links

$: screen -r
There are several suitable screens on:
31426..{MY HOST NAME} (Detached)
31434..{MY HOST NAME} (Detached)
Type "screen [-d] -r [pid.]" 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` page.

So now you should have your links up to 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 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.

Last edited by skog; 07-15-2008 at 10:06 AM.
Old 07-15-2008, 01:18 PM   #6
LQ Newbie
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Awesome. Thanks very much.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting/ bash/ a command with 3 parameters mayaabboud Programming 4 01-05-2008 10:22 AM
Bash scripting: redirecting input to a command hal8000b Programming 2 12-10-2007 07:29 AM
Wrong parsing of ls command in bash scripting itz2000 Programming 3 04-25-2007 10:23 AM
Bash Scripting - echo command question gbhil Programming 2 04-27-2005 07:27 PM
Bash command scripting otisthegbs Linux - General 6 07-06-2004 12:06 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration