LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2017, 08:44 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 10
Post Move a command to background.


Hello.
I like to move a command to background and I found "bg" and "fg" commands but I like when I move command to background then its running and not show me the result suddenly when its finished. For exmaple:
Code:
$ sudo nmap -A IP
$ bg
[1]+ sudo nmap -A IP &
In above example, when the nmap command finished then it show the result in the terminal suddenly.

Thank you.
 
Old 09-02-2017, 10:49 AM   #2
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,840

Rep: Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738
Quote:
Originally Posted by hack3rcon View Post
Hello.
I like to move a command to background and I found "bg" and "fg" commands but I like when I move command to background then its running and not show me the result suddenly when its finished. For exmaple:
Code:
$ sudo nmap -A IP
$ bg
[1]+ sudo nmap -A IP &
In above example, when the nmap command finished then it show the result in the terminal suddenly.

Thank you.
That is not quite how background works. You could background it using the command-line
Code:
sudo nmap -A IP &
and get an effect something like that. Several of the other ways to background detach the process from the terminal so you need to redirect the output.

To use bg and fg you need to run the process, then CRTL-Z to stop the process and regain control, then bg will push it into the background. fg would recover it to the foreground. Easier to just start it in the background if that is your intent (or use screen).

All of this information and more is readily available at dozens of sites online. a search with duckduckgo, google, bing, or evn yahoo search would turn up tutorials and references.
 
Old 09-02-2017, 11:37 AM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,768

Rep: Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797Reputation: 797
Once a command is started in the foreground you have to pause it with Ctrl-Z,
then you can continue it with bg (or fg) command.
 
Old 09-02-2017, 10:52 PM   #4
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
OP asking: "NOT show me the result suddenly when its finished"

set +m
https://superuser.com/questions/3059...inishes-execut
That's for just the "done" msg; redirecting output > is a different beast.

Web-researching is always best, but coming up with just the right keywords is the trick!!!

Last edited by !!!; 09-02-2017 at 11:08 PM.
 
Old 09-03-2017, 04:33 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,622

Rep: Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610
I do not really understand what do you want to do with your command if you do not want to see the result.
By default nmap scans the net and reports the result. If you suppress the result you will lost it.
You ought to read about redirection to save the output (see man bash).
(or probably I misunderstood something?)
 
Old 09-03-2017, 05:46 AM   #6
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by wpeckham View Post
That is not quite how background works. You could background it using the command-line
Code:
sudo nmap -A IP &
and get an effect something like that. Several of the other ways to background detach the process from the terminal so you need to redirect the output.

To use bg and fg you need to run the process, then CRTL-Z to stop the process and regain control, then bg will push it into the background. fg would recover it to the foreground. Easier to just start it in the background if that is your intent (or use screen).

All of this information and more is readily available at dozens of sites online. a search with duckduckgo, google, bing, or evn yahoo search would turn up tutorials and references.
Excuse me, I forgot to show the full command:
Code:
$ sudo nmap -A
Starting Nmap 6.47 ( http://nmap.org ) at 2017-09-02 15:06 PDT
^Z
[1]+  Stopped                 sudo nmap -A IP
When I did "command &" then it cause some problem. for example, run "ping google.com &".
 
Old 09-03-2017, 05:58 AM   #7
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,840

Rep: Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738
#1 ping has no output until it ends. If you used
Code:
ping -c 3 google.com &
so that it terminates after three packets and you would get the output when ping exits. The more general case would require you to redirect STDOUT and STDERR and examine them later.

The best case is to use something like screen (I like to handle it with screenie) so my command is running in a different virtual terminal session and I can go look at the output at my leisure. Is there anything that prevents you from using such a solution?
 
Old 09-03-2017, 06:11 AM   #8
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by pan64 View Post
I do not really understand what do you want to do with your command if you do not want to see the result.
By default nmap scans the net and reports the result. If you suppress the result you will lost it.
You ought to read about redirection to save the output (see man bash).
(or probably I misunderstood something?)
I need something like switch. when the nmap finished then I switch to it and see the result.
 
Old 09-03-2017, 06:12 AM   #9
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by wpeckham View Post
#1 ping has no output until it ends. If you used
Code:
ping -c 3 google.com &
so that it terminates after three packets and you would get the output when ping exits. The more general case would require you to redirect STDOUT and STDERR and examine them later.

The best case is to use something like screen (I like to handle it with screenie) so my command is running in a different virtual terminal session and I can go look at the output at my leisure. Is there anything that prevents you from using such a solution?
"ping" command is a problem and I see the result and even can't stop it. I used "kill" command for stop it
 
Old 09-03-2017, 08:52 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,426
Blog Entries: 10

Rep: Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248Reputation: 5248
i think op really needs several terminal windows.
or if no gui, screen or tmux.
 
Old 09-03-2017, 10:59 AM   #11
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,622

Rep: Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610Reputation: 5610
Quote:
Originally Posted by hack3rcon View Post
I need something like switch. when the nmap finished then I switch to it and see the result.
I would suggest you the tool named screen (as it was already told). Or just use several terminals instead of one.
 
Old 09-03-2017, 08:26 PM   #12
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,840

Rep: Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738Reputation: 1738
Quote:
Originally Posted by hack3rcon View Post
"ping" command is a problem and I see the result and even can't stop it. I used "kill" command for stop it
Use the -c option to limit the number of iterations to make it terminate, or send it CTRL-C to interrupt it and cause exit.

You really should investigate screen and screenie. I think you will like them a LOT.
 
Old 09-06-2017, 01:30 AM   #13
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by pan64 View Post
I would suggest you the tool named screen (as it was already told). Or just use several terminals instead of one.
"screen" is a good tool and I used it some years ago.
 
  


Reply


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
LXer: Ask Safia: How do I move from a proprietary software background into open source? LXer Syndicated Linux News 0 05-24-2016 06:41 PM
[SOLVED] Using shell script how can I move text lines up over an unchanging background waddles Slackware 6 10-31-2013 03:28 AM
how to move background process to foreground batola Linux - Server 29 03-10-2010 10:28 AM
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 12:01 PM
startx on Debian gives grey background - cannot move mouse cursor or type fdac Linux - Newbie 7 05-04-2005 03:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:33 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
Open Source Consulting | Domain Registration