LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-16-2006, 01:46 PM   #1
DavidHB
Member
 
Registered: Feb 2006
Location: Chile
Distribution: Slackware 10.2
Posts: 53

Rep: Reputation: 15
I need to run screen from a script


I need to run "screen" from a script. Is it possible? Is a there a substitue?

What I need to do is start a session run a program and then remotely be able to connect to that session and see the stdout results. Needs to be in real time, so having the program write to a file and then read the file remotely from another console doesn't do it.

???

Dave
 
Old 12-16-2006, 02:17 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 328Reputation: 328Reputation: 328Reputation: 328
TCL/Expect was made for this. You can use screen as part of the process. For example:

Code:
#!/usr/bin/expect
set error 0

spawn -noecho /usr/bin/ssh user@host

expect "$ "
after 1000
send "screen\r"

expect {
   "$ " {
      after 1000
      send "ls\r"
   }
   timeout {
      set error 1
   }
}

after 1000
send "\01\04"

exit $error
This will connect via ssh to user@host, run screen, issue the command 'ls' and disconnect. When you reconnect to the session, you will see the output of the 'ls command.

Update: I changed the code to not wait for the completion of the command ("ls" in the example), since I think you want to use this to start a long running command.

Last edited by macemoneta; 12-16-2006 at 02:27 PM.
 
Old 12-16-2006, 11:59 PM   #3
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Why not just launch the screen session in a detached mode?

From the man page:

Code:
-d -m      Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
/usr/bin/ssh user@host /usr/bin/screen -d -m /path/to/command

The only downside to this is if the command you execute terminates, it will kill the screen session. But if it's a command that is long running or running a continuous daemon or service, shouldn't give you too much problems as easy way to start the screen and come back to it later to see what's going on if there's console output.
 
  


Reply

Tags
screen, script


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
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 04:23 AM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 03:53 AM
How to turn off screen blanking screen saver in run level 3? Arodef Linux - Software 1 01-04-2005 01:50 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 10:34 AM
can't run a script script from icon in konqueror scottsteibel Linux - Software 1 08-02-2003 08:59 PM


All times are GMT -5. The time now is 09:07 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration