Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


dt



326 posts

Ultimate Geek
+1 received by user: 41


Topic # 242973 22-Nov-2018 09:06
Send private message quote this post

Hi,

 

So I have recently started playing with ubuntu server and have a few services running on it which im having some difficulty selecting and when I say difficulty I mean I have no idea how to select them again :-)

 

I execute a script which launches a listen server and after the listen server is up and running I've just been doing ctrl+z to break out of it

 

I've tried my best to google this, as I have with everything else I've learnt but since my knowledge is so limited on the subject I don't believe im googling the correct terms to get the correct results

 

Help appreciated as always

 

TIA

 

DT


Filter this topic showing only the reply marked as answer View this topic in a long page with up to 500 replies per page Create new topic
 1 | 2
923 posts

Ultimate Geek
+1 received by user: 605

Trusted

  Reply # 2131512 22-Nov-2018 09:13
Send private message quote this post

What version of ubuntu are you running? I haven't used it in a few years but iirc it sounds like you want to run this in a screen.

 

screen -d -m -t nameofscreen sh myscript.sh

 

You may want to look into having it run it as a service so it will launch at startup automatically


131 posts

Master Geek
+1 received by user: 43


  Reply # 2131513 22-Nov-2018 09:13
Send private message quote this post

Handy link for you: ctrlz-and-ctrlc-in-unix-command-line

 

Short story:

 

use 'fg' to bring it back

 

 

 

 


 
 
 
 


484 posts

Ultimate Geek
+1 received by user: 95


  Reply # 2131515 22-Nov-2018 09:17
Send private message quote this post

evnafets:

 

Handy link for you: ctrlz-and-ctrlc-in-unix-command-line

 

Short story:

 

use 'fg' to bring it back

 

 

Should add: fg to bring it back to the foreground.

 

Use bg to send it to run in the background.

 

To me the OP wasnt all that clear what is trying to be achieved. Are you trying to run the script as a service?


14267 posts

Uber Geek
+1 received by user: 2590

Trusted
Subscriber

  Reply # 2131548 22-Nov-2018 09:35
One person supports this post
Send private message quote this post

service start (servicename)

 

This typically runs a script that lives somewhere in the /etc folder.





AWS Certified Solution Architect Professional, Sysop Administrator Associate, and Developer Associate
TOGAF certified enterprise architect
Professional photographer


493 posts

Ultimate Geek
+1 received by user: 131


  Reply # 2131563 22-Nov-2018 09:51
One person supports this post
Send private message quote this post

timmmay:

 

service start (servicename)

 

 

service <servicename> start. Other command produces "start: unrecognized service" :P


5071 posts

Uber Geek
+1 received by user: 1198

Moderator
Trusted
Lifetime subscriber

  Reply # 2131566 22-Nov-2018 09:54
Send private message quote this post

Why Ubuntu?  I use CentOS but everyone has a preference I guess.  Ubuntu hasn't been great in recent versions from what I hear.


dt



326 posts

Ultimate Geek
+1 received by user: 41


  Reply # 2131567 22-Nov-2018 09:54
Send private message quote this post

Yeah sorry guys if im not making much sense, still an ultra n00b 

 

I'm running Ubuntu 16.04.5 LTS (latest supported version for the server im running on it)

 

After reading the link above it looks like ctrl+z isn't the correct command for me to use as I dont want to suspend the service, its the only command I could figure out to "break out" so I could get the command line back

 

I'll try and explain what im trying to achieve a little better

 

I run my listen server by executing a script via ./myserver.sh

 

this gets my server up and running but it takes over the whole terminal (ssh'd in via putty)

 

in the Microsoft world I would say its in my focus and I want to minimize it so I can get back to the OS, but then I also want to switch back to it when I want access to the listen servers console

 

hope that makes more sense? 

 

 


dt



326 posts

Ultimate Geek
+1 received by user: 41


  Reply # 2131573 22-Nov-2018 10:04
Send private message quote this post

gehenna:

 

Why Ubuntu?  I use CentOS but everyone has a preference I guess.  Ubuntu hasn't been great in recent versions from what I hear.

 

 

 

 

Its the recommended/supported os of what im trying to do

 

I originally had 18.04 LTS running but kept running into problems with the listen server because of it.. big learning curve for a windows server guy :) 


484 posts

Ultimate Geek
+1 received by user: 95


  Reply # 2131614 22-Nov-2018 10:13
Send private message quote this post

dt:

 

Yeah sorry guys if im not making much sense, still an ultra n00b 

 

I'm running Ubuntu 16.04.5 LTS (latest supported version for the server im running on it)

 

After reading the link above it looks like ctrl+z isn't the correct command for me to use as I dont want to suspend the service, its the only command I could figure out to "break out" so I could get the command line back

 

I'll try and explain what im trying to achieve a little better

 

I run my listen server by executing a script via ./myserver.sh

 

this gets my server up and running but it takes over the whole terminal (ssh'd in via putty)

 

in the Microsoft world I would say its in my focus and I want to minimize it so I can get back to the OS, but then I also want to switch back to it when I want access to the listen servers console

 

hope that makes more sense? 

 

 

 

 

 

 

So the quick and simple solution might simply be:

 

 ./myserver.sh &

 

The & will tell your shell to run it in the background and return the prompt to you.  The issue is that you'll have to do this manually everytime you want to start your service.  If you want it to happen automatically whenever you restart your host you'll need to create a systemd service.  For that part start here: https://askubuntu.com/questions/919054/how-do-i-run-a-single-command-at-startup-using-systemd  But before you get there...lets make sure the above is what you want


dt



326 posts

Ultimate Geek
+1 received by user: 41


  Reply # 2131628 22-Nov-2018 10:29
Send private message quote this post

nzkc:

 

So the quick and simple solution might simply be:

 

 ./myserver.sh &

 

The & will tell your shell to run it in the background and return the prompt to you.  The issue is that you'll have to do this manually everytime you want to start your service.  If you want it to happen automatically whenever you restart your host you'll need to create a systemd service.  For that part start here: https://askubuntu.com/questions/919054/how-do-i-run-a-single-command-at-startup-using-systemd  But before you get there...lets make sure the above is what you want

 

 

 

 

it sounds like it, will give it a go in a few moments.

 

if it does do what I want, should I be able to use fg to bring it back into view ? 


484 posts

Ultimate Geek
+1 received by user: 95


  Reply # 2131785 22-Nov-2018 12:39
Send private message quote this post

Yes. And you can use the jobs command to see what background tasks you have.  Do note that if you logout of that session that job will stop.  You need to use nohup or screen to avoid that.


97 posts

Master Geek
+1 received by user: 56


  Reply # 2131820 22-Nov-2018 13:23
One person supports this post
Send private message quote this post

nohup ./myserver.sh > /var/log/myserver.log 2>&1 &

 

nohup - so you can logout without terminating script
> - /var/log/myserver.log - send STDOUT to log file (use >> if you want to append to existing log)
2>&1 - send STDERR to the same place a STDOUT
& - background the job

 

 


348 posts

Ultimate Geek
+1 received by user: 53


Reply # 2131831 22-Nov-2018 13:35
Send private message quote this post

Or open up a second SSH window. You can run loads at the same time (unlike Windows :-p)


470 posts

Ultimate Geek
+1 received by user: 261


  Reply # 2131838 22-Nov-2018 13:37
One person supports this post
Send private message quote this post

For something like a server that runs often and for long periods of time, I highly recommend creating a systemd service rather than using any of the other methods. Once set up, it's easy to make the server run automatically on startup, restart if stopped, or start/stop it at will.

 

If you'll run this server only once in a while, and aren't bothered about being able to do any of the things above, then just use screen.


14267 posts

Uber Geek
+1 received by user: 2590

Trusted
Subscriber

  Reply # 2131844 22-Nov-2018 13:44
Send private message quote this post

stinger:

 

timmmay:

 

service start (servicename)

 

 

service <servicename> start. Other command produces "start: unrecognized service" :P

 

 

You need to set it up as a service. It's not that difficult. With that it's easy to start on system start, the OS will ensure it stays up, that kind of thing.





AWS Certified Solution Architect Professional, Sysop Administrator Associate, and Developer Associate
TOGAF certified enterprise architect
Professional photographer


 1 | 2
Filter this topic showing only the reply marked as answer View this topic in a long page with up to 500 replies per page Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.