You are not logged in.

#1 2008-09-25 21:05:06

pogeymanz
Member
Registered: 2008-03-11
Posts: 1,020

Very simple bash question.

Long story short: I use SSH to connect to my work computer, but the connection gets dropped after a certain number of hours (It's supposed to, I just don't know why). I have some jobs that I send that take longer than the allowed time, so the solution is to use nohup:

nohup command

So that when my ssh dies, the job is still running.

But I want to have this computer chugging along all weekend with several commands. Would I do this?

nohup command1 && nohup command2 && nohup command3

Also, what if I write a very short script with all these commands in it and then just ran:

nohup script

That would be nice, but I don't know how to write a bash script at all. Do I just make a list of commands and save it as script.sh?

Offline

#2 2008-09-25 21:33:14

daf666
Member
Registered: 2007-04-08
Posts: 470
Website

Re: Very simple bash question.

did you try screen?

Offline

#3 2008-09-25 22:41:55

pogeymanz
Member
Registered: 2008-03-11
Posts: 1,020

Re: Very simple bash question.

Don't I have to have screen installed on the work computer to do what I'm doing? I don't have root privileges, so I can't install stuff.

Offline

#4 2008-09-25 22:50:32

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: Very simple bash question.

pogeymanz wrote:
nohup command1 && nohup command2 && nohup command3

Untested, but I think that would fail...  I would try

nohup $(command1 && command2 && command3)
pogeymanz wrote:

Also, what if I write a very short script with all these commands in it and then just ran:

nohup script

That would be nice, but I don't know how to write a bash script at all. Do I just make a list of commands and save it as script.sh?

A bash scrpit is easy...

#!/bin/bash

command1
command2
command3

Offline

#5 2008-09-26 00:04:56

pogeymanz
Member
Registered: 2008-03-11
Posts: 1,020

Re: Very simple bash question.

Allan wrote:

Untested, but I think that would fail...  I would try

nohup $(command1 && command2 && command3)

A bash scrpit is easy...

#!/bin/bash

command1
command2
command3

Thank you. I knew it would be simple- but knowing it's simple and knowing what to do are two different things. wink

And from now on I'll know to use parantheses too. Sweet.

Last edited by pogeymanz (2008-09-26 00:05:36)

Offline

#6 2008-09-26 02:10:24

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Very simple bash question.

Don't do:

nohup $(commands...)

unless the commands are going to print as a result something that can be executed. For instance, this won't work:

nohup $(echo 10)

because it will turn into:

nohup 10

and you'll get an error message to the effect "command 10 not found". This would work:

nohup $(echo "echo 10")

but I don't know whether the nohup will kick in before the $(...) part has returned. For all I know, it could be that this:

nohup $(long-running-command)

will only have nohup-protection _after_ long-running-command has finished. You may have better luck with one of these constructions:

nohup ( command1; command2; command3 ) # or you could put '&&' between the commands, it won't matter
nohup { command1; command2; command3; }

I don't know whether they will work though, I haven't played around with this. Conceivably you might have to escape the '{'s or '('s. Or do this:

nohup bash -c "command1; command2; command3"

Well, there's no answer here but perhaps it'll help you find one, or prompt someone else who does know the answer...

Offline

#7 2008-09-28 03:57:48

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Very simple bash question.

pogeymanz wrote:

Don't I have to have screen installed on the work computer to do what I'm doing? I don't have root privileges, so I can't install stuff.

If you have access to a compiler, compile your own and throw it in $HOME. I also cannot imagine any serious server NOT having screen...

Offline

Board footer

Powered by FluxBB