LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-07-2010, 11:44 AM   #1
tirwit
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Rep: Reputation: 0
Sending commands to a screen session


Hi!

I have several screen sessions running, one of them named 'test'. I want to send a simple command to there without attaching the screen, so I do:

screen -S test -X ls

But when I attach the screen to see if it has done something, nothing is different... How can I send commands then?

Of course the 'ls' command is not what I want to do, but it's just an example in how this is not working. :-)
 
Old 08-07-2010, 12:19 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
Try
Code:
screen -S test -X stuff ls
The '-X' option executes screen commands. 'ls' isn't a screen command, but stuff is. The argument to stuff is then a string which gets stuffed into the specified session. I use this method quite a bit to launch interactive applications at boot time.

--- rod.
 
1 members found this post helpful.
Old 08-08-2010, 06:50 AM   #3
tirwit
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Aha ok... And what should I put at the end of the string for it to execute the command, since using just "stuff ls" it just sends the string without executing it?
 
Old 08-08-2010, 12:45 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
Ahh, yes; that little complication....
Code:
screen -S test -X stuff "ls -las"`echo -ne '\015'`
Note carefully the specific use of quotes and backticks.

--- rod.
 
1 members found this post helpful.
Old 08-08-2010, 02:02 PM   #5
tirwit
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Where can I find all the options for each unix command? Because I'm trying to understand what the "ls -las" and "echo -ne" do, but can't find reference to those options in the man pages, or the internet for that matter... I'm still new around here.

What documentation should I look for, to see what is that "\015"?

Last edited by tirwit; 08-08-2010 at 02:14 PM.
 
Old 08-08-2010, 08:19 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by tirwit View Post
Where can I find all the options for each unix command? Because I'm trying to understand what the "ls -las" and "echo -ne" do, but can't find reference to those options in the man pages
The man pages are a great reference, but it can take a while to get used to reading them. I'm suspecting that in this case you are having trouble since you may be looking for an "-las" option in the "ls" manpage. However, there is no "-las" option. It is simply the "-l", "-a" and "-s" options combined.

Quote:
What documentation should I look for, to see what is that "\015"?
Try the "ascii" man page.

Cheers,

Evo2.
 
Old 08-08-2010, 09:46 PM   #7
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
To explain the immediate question, because there is a fair bit of obscuratta there:
\015 is the octal value of 'newline'/'carriage return'. Putting it in single quotes makes the backslash into not-an-escape, so it denotes a single byte, in octal radix. It is echoed without appending a newline (-ne), which sounds completely redundant, but I think I found it had be like that, and I don't understand why. The output of echo is turned into a commandline argument using the magic of `backticks` and which should be replaced with the preferred $(not_backticks_anymore) notation. It gets appended to the commandline, as the final character of the stuff argument. The double quotes would be unnecessary, if we just wanted the bare ls command, but I like my ls a bit fancier.

The good news is, you aren't likely to bump into anything much weirder than this. Possible, but not often. Screen itself is a bit of an odd thing (but a very useful one), and everything around it seems to be a bit on the fringe, too.

The man pages are great for finding out what existing commands do, but not so much for figuring out what to use to solve your problems. For that, experience is the best reference. And Google. A lot of commands are built into the shell, and for those you'll get dumped into the bash manpage, left to find the particular command on your own. There is also the somewhat arcane 'info' pages, which require some learning to get around the system.


--- rod.

Last edited by theNbomr; 08-08-2010 at 09:49 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending AT commands to a SMS modem narmida Linux - Hardware 2 09-24-2009 01:05 PM
sending AT commands to wavecom through C code nathan Linux - Newbie 2 08-11-2009 09:27 AM
Sending HP Printer Commands cmnorton Programming 2 12-10-2007 07:58 AM
Creating a screen session in an existing session Frits of waterplant Linux - Newbie 4 01-18-2007 04:53 AM
sending at commands over pppoe? sti2envy Linux - Networking 3 10-18-2005 06:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:12 PM.

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