You are not logged in.
Pages: 1
This is something that's been bothering me for quite some time. Say I am running a server that's console based(no gui) but it's urnning in the background, every once in awhile I want to bring it up so I can type a few commands in, is their a way to bring hidden cnonsole apps back up in the terminal?
Offline
'screen' is your friend.
you can detach from it, logout, login later, and then reattach.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
'screen' is your friend.
you can detach from it, logout, login later, and then reattach.
Sorry i don't understand what you mean, can you be more in detail?
Offline
Yup ... as cactus indicates screen is the solution.
Just for clarifications screen will act as a "program wrapper" so say you want to connect to a server over ssh, you can do :
screen -t remoteserver ( this gives your instance a name "remoteserver").
Screen starts and you can then issue the connect command say:
ssh you@the_remote_server
once you connect you press Ctrl+d to disengage screen (but remains active in the background).
An hour later you need to go to the server again, so you re-engage the process with screen -r -t remoteserver
and you are back to the exact point you were before.
Naturally, this also works for programs working in the local machine not just for remote access.
Offline
Alright, so for example i can run:
screen -X foo -t foofoo
foo being the command I want to run, and foofoo being the title of the screen?
Offline
Yup.
Then to disengage you type Ctrl + a and then d ( I made a mistate in my first explanation)
Then when you want to go back you type: screen -r -t foofoo
Offline
As he said Screen is your friend, I use it on my everyday work wether on the server to run IRSSI and mp3player or the laptop for any thing i do, here's a little howto (VERY little one!)
First pacman -S screen lol
you start screen by invoking
<code>screen</code>
but the more appropriate way is to run it via
<code>screen -DR</code>
-DR tell screen to detach any attached screen (that belongs to ur username of course) and logout, i mean if you had a session on ur server for example running from the server itself, screen will quit and will logout the user automatically, and if u had already an ssh screen session, session will quit it and close that ssh connection ( <code>screen -Dr</code> same behaviour but doesn't logout/close ssh)
In screen ^a (^ means Ctrl so Ctrl+a) is the key to everything,
^a ^c : open new screen (new tab if u want)
^a A : Rename the current screen (tab)
^a d : detach the screen
^a DD : detach and logout/close ssh
^a x : lock the screen need a password to unlock it (or simply attach it elsewhere)
^a k : close the current tab
^a SPACE : next tab
^a BACKSPACE : previous tab
^a ' : Specify tab number
^a " : tab menu
^a ^a : Jump to previously used tab, very helpfull when u're working on sth on 2 tabs
^a ^ : kill all tabs and quit
^a l : redraw the current screen
^a S : split the screen
^a TAB : Jump to the next splitted part of the screen
Tutorial : http://rucus.ru.ac.za/docs/screen/Backtick.html
and If phrakture doesn't mind, his config which i use and love
.screenrc : http://phraktured.net/config/.screenrc
.screen : http://phraktured.net/config/.screen/
BTW I run a screen inside a screen, from the screen that runs locally, screen connects automatically to the server and i launch screen from it, but to accomplish this add
<code>escape ^Qq</code>
to the server's .screenrc so ^a will become ^q (change it to whatever u want)
Enjoy
[My Blog] | [My Repo] | [My AUR Packages]
Offline
_Gandalf_, very nice.
Just one thing, to detach you only do ^a then press "d" (as opposed to ^a ^d).
Offline
Yep ralvez, sorry I use ^a DD more often and it sliped my mind
thx
[My Blog] | [My Repo] | [My AUR Packages]
Offline
Alright, you talk about about SSH, which isn't what I am running. I'll give you an example, but I'm pretty sure I can figure it our myself. I have a script that runs a game server:
#!/bin/sh
while true; do
/dir/foo/fooserver
done
But, unfortunately that makes the console hidden so I can't access it anymore, which hopefull the 'screen' thing you're talking about will solve my little issue. So, if I want to start the server instead, I should do something like:
#!/bin/sh
while true; do
screen -DR && screen -t fooserver && screen -x fooserver
done
Seomthing around those lines?
Offline
Wait, the server need to be run again and again and again ? coz of the script above the file is executed endless times, is it what u're looking for ??
[My Blog] | [My Repo] | [My AUR Packages]
Offline
I would assume that multi-runs of the same server would create enough forks that eventually the system would crash... not a good idea, if you ask me. :?
Offline
Currently:
#!/bin/sh
while true; do
/dir/foo/fooserver
done
Just restarts the server if it closes, it doesn't keep opening and opening ect. IE: Server crashes, it's automatically braught back up.
Offline
Oh, ok here's what you can do, install screen then do:
screen -DR
a screen will open with a bash of the current user, now do
while true; do /dir/foo/fooserver; done
And this way, the server will run, it will stay on the screen, plus from anywhere you can bring that screen up (by screen -DR) and stop it (serval Ctrl+c) or just monitor it... that would be a good idea
If you intend to only use it as a server and you don't want to monitor it but to start/stop it and in case it crashed launch it back, then create and rc.d script, that will output a pidfile and use monit to monitor it and automatically lauch it in case it fails (tell me if u need instructions...)
[My Blog] | [My Repo] | [My AUR Packages]
Offline
Currently:
#!/bin/sh while true; do /dir/foo/fooserver done
Just restarts the server if it closes, it doesn't keep opening and opening ect. IE: Server crashes, it's automatically braught back up.
That surprises me... if there was a 'wait' in there, I'd be less skeptical.. I believe you mind, it just shocks me that the thing doesn't spawn a gabillion fooservers
.oO Komodo Dave Oo.
Offline
It surprises me too. If I so somthing like:
INST=`ps -A | grep -c process_name`
if [ "$INST" == 0 ]; then ...
I would think there is a programmatic constraint to prevent continual forking of the same action over and over ... but hey, what do I know
Offline
It depends whether fooserver detaches itself from the shell and runs in the background or not. Doesn't it?
Try this
$ while true; do echo Hello; sleep 10; done
Now this
$ while true; do echo Hello; sleep 10 &
> done
Note: the then newline works the same as the semi colon, bash doesn't seem to like an ampersand then a semi colin.
Be warned, the second example will executed `sleep 10` over and over as fast as it can, so be ready with ctrl-c
if fooserver runs in the shell then it the loop will only iterate when the current instance of fooserver is killed
Offline
Pages: 1