Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Its pretty powerful so probably best if you read its manual pages but essentially once you have logged in via ssh (or anything else) run `screen` and then you will be in what is termed a screen session.
You can run whatever long running tasks you like and when you detach from the screen (by pressing ctrl-a, d) you will be back at your normal terminal session. You can then log out. Log back in again. If you run `screen` again it actually creates a new screen session, to reattach to your previous existing screen session run `screen -r`.
Screen is amazingly useful and has a lot of nice features, I suggest you check it out.
'nohup' may also do the trick for you if you want something simpler. 'screen' is a better choice for anything interactive.
Screen has the capability to launch a command to run within a new screen session. Once the command is complete, it will usually exit the screen session or you can invoke an exit yourself. Makes it nice to be able monitor the command if its still running til its done. read the screen man page for all available options.
Screen has the capability to launch a command to run within a new screen session. Once the command is complete, it will usually exit the screen session or you can invoke an exit yourself. Makes it nice to be able monitor the command if its still running til its done. read the screen man page for all available options.
Correct if you lauch it as "screen <command>"
But normally I just run "screen" to get the screened shell and then hack away in there.
It's useful to get into the habit of running "screen" as soon as you log in so that if you're accidentally disconnected you can carry on from where you left off. I recently discovered all the split-screen stuff it can do, very timesaving!
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,795
Rep:
Quote:
Originally Posted by simplified
[snip]
- logging on via ssh
- run the script in the background
- logoff ssh session
- go down the pub
- come back home, job done!
Does anyone have any ideas?
Cheers, Simp.
Someone else already mentioned "nohup" as a way to do this.
Another is to submit the script to batch:
Code:
at -f path-to-script now
or
Code:
at -f `pwd`/script now
The first example is sort of generic. The second example is one I use most since I'm in the directory containing the script already (and I'm too prone to mistyping the full path).
You do need to have the "atd" daemon running in order to do this.
Distribution: Kubuntu 9.04 x64 / Ubuntu Server 9.04 x64
Posts: 50
Original Poster
Rep:
Hi All
Many thanks for all of your responses! As with anything *nix it's cool that there's several ways to do the same thing - with us all with our favourites. I have to say that the nohup method was the one that I liked the best as my script does log the changes made along with any errors.
However, to anyone reading this thread that didn't know how to do it don't forget the "&" at the end of the command for nohup. I'm embarrassed to say that I was banging my head against the wall until I had a "oh yeah, of course" moment and popped the "&" in. For example, if you wanted to ping another machine 100 times you would use:
$ nohup ping -c 100 192.168.1.1 &
Just thought that I'd point that out for anyone not in the know, caught my out!
Yeah, '&' puts a process in the background, but its still 'attached' to the originating terminal session. Hence the need for nohup to disconnect as well.
FYI nohup = no hangup, from the orig arpanet when everything was done over phone lines.
However, to anyone reading this thread that didn't know how to do it don't forget the "&" at the end of the command for nohup. I'm embarrassed to say that I was banging my head against the wall until I had a "oh yeah, of course" moment and popped the "&" in.
If you forget the ampersand, you can usually:
type Ctrl-Z to suspend the job,
type bg to resume the job in the background.
Try man bash and scan for "jobspec" for more details/options.
In addition, to bg the disown -h option will apparently do what "nohup" would after the fact.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.