From kragen@dnaco.net Tue Sep 29 17:21:47 1998 Date: Tue, 29 Sep 1998 17:21:45 -0400 (EDT) From: Kragen To: systalk@ml.org Subject: Re: [ST] Starting jobs in the background in UNIX In-Reply-To: <01bdebd6$eceb1540$0b4515c4@fireclaw.icon.co.za> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Status: O X-Status: On Tue, 29 Sep 1998, Sean Preston wrote: > I am trying to start a set of commands in the background. I know the one > way is to use the at command and give it a file with the commands in it. I > do not have access to this. I was told there is a way of doing it using > nohup but I am unsure as to how to give this command the file with all of my > commands in it. I am doing this through a telnet session as I am not going > to have access to the console of the system. I have permission to start > jobs in the background. > > The main reason I need to start the commands in the background is because I > am dialling in from home, starting the commands and then logging off. I > need it to continue while I am not there. There is no screen command on the > system. Well, if it's just a compute job -- something that won't require user interaction -- you can do it as follows: egrep kragen www/logs/access_log > acclog & In this case, I'm starting the 'egrep' command with some arguments and redirecting its output to 'acclog'. It might be a good idea to redirect its standard error to somewhere, too. If you want to do something more complicated, you can write a shell script, like this one: #!/bin/sh ls -l sleep 10 ls -l finger kragen sleep 30 finger kragen (just a bunch of useless commands, in this case, but you can replace them with your own useful ones.) Then you can put the shell script in a file -- say 'myscript' -- and then you can do something like this: bash$ chmod u+x myscript (that makes it executable, indicating it's a shell script, not just a text file) bash$ ./myscript > myscript.out & 'nohup' does something about shielding from the hangup signal, but if your login shell is csh or bash (or something derived from one of them) you don't need to do that. You only need to do that, in fact, if your shell is 'sh'. nohup also automatically redirects the output of your commands, so you don't have to do that by hand. You can run it like this: bash$ nohup ./myscript & You can give any command this way -- egrep if you want: bash$ nohup egrep kragen www/logs/access_log > myaccesses & Later on, you can use 'ps' to see if your job is still running: bash$ ps -elf | egrep myscript ps -elf shows all the processes on your (Solaris or other System V) system, including all their arguments; the 'egrep' will filter out most of them, except those that have the string 'myscript' in them somewhere. If you're using a Linux or BSD-derived system (like SunOS 4) you should use 'ps auxwwwwww' instead of 'ps -elf'. Hope this helps! Kragen -- Kragen Sitaker A well designed system must take people into account. . . . It's hard to build a system that provides strong authentication on top of systems that can be penetrated by knowing someone's mother's maiden name. -- Schneier