Putty and the command line

Hey, I’m new to openSUSE (Ubuntu user) and I have a few questions about it.

I installed openSUSE 11.3 without xwindows so that it boots directly into the command line on my server. I can login fine with putty (ssh) to change settings and manage files but I’d like to know a way to keep a program running after the putty session closes.

Also, are there commands to “minimize” a program and then come back to it later? For instance, I’m running a craftbukkit minecraft server; I want to “minimize” it and download a plugin while keeping minecraft running and come back to it.

From a login with putty, you need to run the command so that it is disconnected from the terminal.

Try: command-name < /dev/null > /dev/null 2>&1 &

This assumes you are using bash as shell.

I just tried running “top” like this and, I got the output:
“[1] 3052”
And the program did not appear to run. Just for the fun of it though, I tried the “jobs” command and I got this line:
“[1]+ Exit 1 top < /dev/null > /dev/null 2>&1”

So I assume that this means the program is running? How do I call it back to the screen?

On 2011-03-06 20:36, Viench wrote:

> So I assume that this means the program is running? How do I call it
> back to the screen?

fg


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

On 2011-03-06 18:06, Viench wrote:
>
> Hey, I’m new to openSUSE (Ubuntu user) and I have a few questions about
> it.
>
> I installed openSUSE 11.3 without xwindows so that it boots directly
> into the command line on my server. I can login fine with putty (ssh) to
> change settings and manage files but I’d like to know a way to keep a
> program running after the putty session closes.

There is a command I can’t remember that does that, detach a program from
the terminal and access it again from another terminal, even after you log out.

Ah, screen! From an old post in the mail list:

[SLE] background process and controlling terminal / 2003 07 15 / Jason

Have a look at screen. At a terminal, type ‘screen’ and press return after
the copyright and pizza notice. Start your lengthy processes as normal.
Ctrl-A-D detaches the screen, or you can just close the terminal. Open up
another xterm and type “screen -r”, and it attaches itself to the terminal.

I use it for monitoring KDE CVS compiles from work. Start the compile
script from within screen in Konsole at home, and use Putty to ssh into my
box and use ‘screen -r’ to see if the compile is continuing OK.

> Also, are there commands to “minimize” a program and then come back to

No way. Minimize is an ‘X’ concept, and you have no ‘X’ running.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

New issue, when I try the “command-name < /dev/null > /dev/null 2>&1 &” now I get no output and nothing when I type “jobs”.

Any ideas?

Also, I’d like to know more about the “< /dev/null > /dev/null 2>&1 &” commands. Would anyone care to tell me more about them or point me in the direction of some documentation?

Sorry to double post, but I couldn’t edit my post for some reason.

“Screen” seems to work well for my putty needs. However is there a way to have more than one at a time, and see a list of the screens I have running?

Also, I didn’t mean minimize in the traditional X sense. I was referring to letting me manage files and such while programs I started are running. It is not necessarily in reference to this server, but it is general command line knowledge that I would like to know anyway.

I can login fine with putty (ssh) to change settings and manage files but I’d like to know a way to keep a program running after the putty session closes.

Use nohup


nohup command-name &

Hiatt

I like this command much more than < /dev/null > /dev/null 2>&1 &. (Easier to remember) How do I call back the program with fg though?

On 2011-03-06 22:06, Viench wrote:

> Also, I’d like to know more about the “< /dev/null > /dev/null 2>&1 &”
> commands. Would anyone care to tell me more about them or point me in
> the direction of some documentation?

Pipes.
Dustbin.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

On 2011-03-06 22:06, Viench wrote:
>
> Sorry to double post, but I couldn’t edit my post for some reason.

It is in the rules :wink:

> “Screen” seems to work well for my putty needs. However is there a way
> to have more than one at a time, and see a list of the screens I have
> running?

man screen?

> Also, I didn’t mean minimize in the traditional X sense. I was
> referring to letting me manage files and such while programs I started
> are running. It is not necessarily in reference to this server, but it
> is general command line knowledge that I would like to know anyway.

You can have a hundred putty sessions, if you want…

If you mean something else, I haven’t understood your question yet.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

Why would you need to call the program back to the foreground?

> /dev/null 2>&1 and < /dev/null are redirections.
“> /dev/null 2>&1” sends standard output and standard error message to the /dev/null (nowhere)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

screen is almost certainly what you want. Backgrounding a process and
redirecting it STDOUT and STDERR while giving it STDIN from /dev/null is
all well and good as long as you don’t want the interact with the process
ever again, but screen is more flexible than that and I’d be money it’s
what you’re after. With it you can do the following:

Start multiple processes simultaneously. screen has multiple “windows”
that often get overlooked and are basically multiple shells (somebody
mentioned xterm’s, though technically xterm is an X-application and, as a
result, isn’t the right term in this context… just call it a terminal or
shell) within the same screen. Think of screen as your physical screen
(you likely have just one, though maybe you have multiples) and within
that monitor/screen you can see multiple windows… same idea.

Reconnect to previously-started (and non-X) applications. For example I
will often run a single screen on servers that has multiple “windows” with
each dedicated to a task… tail /var/log/messages, tail the firewall
log, run top, watch the system uptime, etc. The nice thing about this is
that applications which do not show the last few hours’ worth of data
naturally (uptime, for example) can be run regularly (every few minutes)
and when reconnecting to that specific “window” within screen I can see
hours’ worth of data, or I can see what’s the latest stuff in my tailed
system log file (/var/log/messages by default) which will just be what is
new since I last looked.

Start processes now that need to last longer than your SSH connection. I
think Carlos mentioned this with regard to compiles; when compiling X and
it’s five minutes before you need to leave you either waste time by
starting the compile later, or leave you computer behind when you likely
need to take it with you. Anytime I’m running something non-trivial on a
remote system I’ll use screen simply because if my connection blips on any
system between myself and the server (excluding the server) all will be
fine until I get back in. I use it a lot for transferring big files
even… if my SSH connection dies at 98% of a 12 GB file it does not make
me happy; with screen, it just doesn’t matter what the client side does.

Share a terminal with somebody else, even another username on the server,
for training, troubleshooting, collaboration of any kind, etc.
More-advanced when using different users, but screen is REALLY powerful in
this way.

screen takes special keystrokes to manipulate it. C-a (Ctrl+a) is the
start (by default) for most of them if not all of them. Case sensitivity
counts so keep that in mind. An example: disconnect from a screen (to go
back to the calling shell):

C-a d
(means Ctr+a followed by (while not holding Control any longer) a single
‘d’ character). emacs users will likely recognize the shorthand.

Create a new window within a screen (Ctrl+a followed by a ‘c’):

C-a c

Rename the current window (kind of nice when you have multiple):

C-a A

Switch to window 0 (the default window):

C-a 0 #yes, that’s a zero, not an O/oh.

Switch to window 1 (you get the idea);

C-a 1

Screen also has its own copy/paste and scrollback (configurable) buffer.
Test with them, as a non-root user in a safe environment, before going too
crazy on a big production machine. If you copy/paste rm -rf / with root
you’ll wish you were dead, like always.

More info: man screen

Good luck.

On 03/06/2011 03:20 PM, Carlos E. R. wrote:
> On 2011-03-06 22:06, Viench wrote:
>>
>> Sorry to double post, but I couldn’t edit my post for some reason.
>
> It is in the rules :wink:
>
>> “Screen” seems to work well for my putty needs. However is there a way
>> to have more than one at a time, and see a list of the screens I have
>> running?
>
> man screen?
>
>> Also, I didn’t mean minimize in the traditional X sense. I was
>> referring to letting me manage files and such while programs I started
>> are running. It is not necessarily in reference to this server, but it
>> is general command line knowledge that I would like to know anyway.
>
> You can have a hundred putty sessions, if you want…
>
> If you mean something else, I haven’t understood your question yet.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJNdFpPAAoJEF+XTK08PnB5lGkQAIdi4gdEnol+xscSI8YTlvBL
rRvrVRu8HvLrfnQ83+MEP3AQqE1TVxzHXBpmuJDKRz2WIJ5sKgwps+uts5RNdWsM
7drIa+qg5GuthYxj2XZtF2BXF1Aft7hSVouQpce14H8DcaDmsx21FXksryvSOgIA
OyoRcXy8NP2sF5CZ/qW+/m212VSG1zCap/qJ7OpjZs+umTQ9Le0PCs+Ncu5Ljs8x
Ti+/engJWiTNKLf03bUYFm8F/wGnT6il25bCs6gRUZIh+aIQWKKfAyaxnqGwrvQO
Nkv5HlCgYVzPGoRkAXQj6ltpqFCBS4mJA0oB5xvyp2B3adKGPXx/Y0qIOJiNxquS
CRqNFMseLAaOBGgnLdZEn0lZP2MilrmLaYtnqxt9tH5sYfDrl7Wu5nXTCRkve6dq
P740JqOOLLe0KL7YbELjjl7hhQJ5JUMwnYlntWsL0bAce5bl6gNfPYpr2aj8CnNg
d4mZ2ObEaUDoklxi0EuOmD9GQH6HaTsMKcC8KoJwqvsNfdZCGPjB5yEUVfJnHdTW
8iJ5hAFVcNTzTZTRr+5W1T3PxKQ6bse3/qNv0GZE0Qjv8KSX/bGVWbNXLasMx8fX
L1WCL/EpkL//nmtBFbtvWoqG5HzqCgkg32tGgp1mbllQ+lvufpCneq70SudikTY1
LhalW3ZXijnYuyf77rTh
=0zEl
-----END PGP SIGNATURE-----

On 2011-03-07 05:08, ab wrote:
> screen is almost certainly what you want.

It is a very interesting command, indeed.

Do you know of a link to a howto for dummies? Or examples of use. :slight_smile:

The manual is excessive, too arid.

> Share a terminal with somebody else, even another username on the server,
> for training, troubleshooting, collaboration of any kind, etc.
> More-advanced when using different users, but screen is REALLY powerful in
> this way.

This one interests me.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don’t know of any offhand, but Google found the following when searching
on ‘screen tutorial linux’:

http://www.cyberciti.biz/tips/linux-screen-command-howto.html
http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/
http://www.kuro5hin.org/story/2004/3/9/16838/14935

I created a presentation a while ago that I could share if interested but
I think these sites probably cover everything and include the dialog that
would normally be provided by a presenter so they may be better options.

Good luck.

On 03/07/2011 07:33 AM, Carlos E. R. wrote:
> On 2011-03-07 05:08, ab wrote:
>> screen is almost certainly what you want.
>
> It is a very interesting command, indeed.
>
> Do you know of a link to a howto for dummies? Or examples of use. :slight_smile:
>
> The manual is excessive, too arid.
>
> …
>
>> Share a terminal with somebody else, even another username on the server,
>> for training, troubleshooting, collaboration of any kind, etc.
>> More-advanced when using different users, but screen is REALLY powerful in
>> this way.
>
> This one interests me.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJNdPmTAAoJEF+XTK08PnB5PdsP/3nHI3/BuFdIXLAZrh2gmzFY
ayAtk74Vl+CKOlDgpaAIz71TPtJTgxUpUC65CxYUUNKaichAMpo9V+e7IMCT0qol
Zf/NxNXGExTJCkEQEYcLaQjyQRtCEmnzuvXl9ykFkDBp4inG7xDPDB6POabtLkbk
DSpIql5G1JSDWM0x8ZjTq3gBpWDikVunbMoR0j4fsVTzSKXgqDpZAO2epCdzoeco
QBAXu9NJ8V9XQk3N5DJGQaR3g0NpM1qZEu7QB4QWWHqhvGyRqr0CzKl5FSLsMXNe
7vqBvdRFqK5GjM3KM2OX+vqOtu3/hKhLLsvDKgSPVPiZpV2wuEnmcW57YAyaBCoe
pkHoqJqHmRDM1TWjcxp7a2wGrcRDMQZotuSSX0KVufmdpm3KIILWr15TJTMdU19q
GpLlJ/wO443uE0HVQePlLQL11tpyiH3vTlgKy4JrliRxy3cnL+cS3IhxZJQPegdA
p4+R/wfSTaGaoK0mLFeQpnfAXLErnXKFReF1+OVR7E7qhxb44nH4crMpkccpCGpe
jgPcfdZOe3p8M38mlQv+UUfBQZCKRPkwWDVhh26JC0oYQNC32cx819XLliouh1Gj
Ft5W6J8cQc9w8vp288hRVuYCJIu1rkeF6GBMY5bAXHG2Pt6WNyu9J5aDOJ+oSvZJ
EWMAZbSKBKpEF9hzJTkO
=5J6h
-----END PGP SIGNATURE-----