LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-25-2006, 12:23 PM   #1
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Rep: Reputation: 15
Screen -X "command"


I am looking to use screen to easily access a running program from my perl script, and am interested in using this function listed in the man pages:

Quote:
-X Send the specified command to a running screen session. You can
use the -d or -r option to tell screen to look only for attached
or detached screen sessions. Note that this command doesnât work
if the session is password protected.
I want to send the screen session a command but I am very confused on how to go about using this -X switch. Please help.
 
Old 08-25-2006, 12:57 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You may be confusing the different acts of sending commands to 'screen' itself, vs. sending commands to the program(s) running in a screen window. It sounds like you want the latter.

You still use the -X option, but accompanied by the 'stuff' command.
An example that might stop a running application...
Code:
screen -X stuff 'exit'
The 'stuff' command is sent to screen, and the argument(s) to the stuff command are entered into the screen window, as if typed at the keyboard. You can embed commands such as this into your perl scripts using the perl 'system()' command.

Hope this helps.

--- rod.
 
Old 08-25-2006, 01:10 PM   #3
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Original Poster
Rep: Reputation: 15
That seems to be getting the command to the screen, but it doesn't enter it (Like the user pressing the enter button. Any idea how to get it to simulate an enter key after the command. Also, how do I specify exactly which screen to send it to?
 
Old 08-25-2006, 01:23 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Usually the enter key sends something like '\r' or '\n' (using perl syntax). That should be part of the string that is 'stuffed'. You specify the screen session with the -S option.

--- rod.
 
Old 08-25-2006, 05:35 PM   #5
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Original Poster
Rep: Reputation: 15
I figured I would get that reply, sorry. I already tried the \n \r for carriage returns within the string, it just treats it as part of the string.

Code:
screen -S 4563.kimball.server -X stuff "say red \r"
Anyother ideas for sending a simulated ENTER, expect maybe?
 
Old 08-25-2006, 07:54 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If you are trying to send the newline from a shell commandline, it is different than from a literal string embedded into perl code.
To send a CR in a bash script, try
Code:
screen -S 4563.kimball.server -X stuff "say red"`echo -ne '\015'`
--- rod.
 
Old 08-25-2006, 09:02 PM   #7
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Original Poster
Rep: Reputation: 15
Thanks! It worked out nicely, just enclosed the above command using backticks, and I'll make the -S name a perl variable. Is there anyway to get it so that screen does not place the PID on the session name?
 
Old 08-25-2006, 10:48 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I think it is always there as part of screen's full name, however I beleive if you open the session with a name, you can reconnect to it by giving that unambiguous name as an identifier. I think...

--- rod.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora Core 2: Screen Resolution can not change from "800X600" to "1024X 768" suhaimi_sj Fedora - Installation 18 12-17-2009 03:29 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 11:49 AM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:03 AM.

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