Professional Web Applications Themes

shell scripts in background (with &) - why would they stop? - Ruby

Shouldn't a Ruby script keep running if someone uses the "&" at the end of the command? I have a script that takes hours to run, processing many files, on a remote server. If I start it like this... /processFiles.rb ... it will work, but I have to keep an SSH terminal window open for hours. If I start it like this... /processFiles.rb & ... and then I close my SSH session to let it run ... it stops immediately after I log out. Is that expected behavior? How would I get it to keep running (like my regular /bin/sh ...

  1. #1

    Default shell scripts in background (with &) - why would they stop?

    Shouldn't a Ruby script keep running if someone uses the "&" at the end of the command?

    I have a script that takes hours to run, processing many files, on a remote server.

    If I start it like this...
    /processFiles.rb
    ... it will work, but I have to keep an SSH terminal window open for hours.

    If I start it like this...
    /processFiles.rb &
    ... and then I close my SSH session to let it run
    ... it stops immediately after I log out.


    Is that expected behavior?

    How would I get it to keep running (like my regular /bin/sh shell scripts) after I log out?

    I could give example code if someone wants to see it.


    Ruby Guest

  2. #2

    Default Re: shell scripts in background (with &) - why would they stop?



    nohup ./processFiles.rb&
    exit

    or

    ruby -e 'fork do exec("./processFiles.rb&") end'

    will make the trick ....

    ronnie.


    Ruby Baby wrote:
     




    Bermejo, Guest

  3. #3

    Default Re: shell scripts in background (with &) - why would they stop?

    Ruby Baby wrote: 
    try:

    trap '' 1
    /processFiles.rb >processFiles.log 2>&1 &

    or with 'nohup', which will do the same for you (redirecting to
    nohup.out, though):

    nohup ./processFiles.rb &
     



    Gennady Guest

  4. #4

    Default Re: shell scripts in background (with &) - why would they stop?

    El Martes, 03 de Febrero de 2004 01:02, Ruby Baby escribió: 

    I'm not sure, but I think no.
     

    Try using the command 'nohup'.
     

    Good luck!



    Imobach Guest

  5. #5

    Default Re: shell scripts in background (with &) - why would they stop?

    >>> How would I get it to keep running (like my regular /bin/sh shell 
    >>
    >> nohup ./processFiles.rb &[/ref]
    >
    > or:
    >
    > disown $(jobs -p) && logout
    >
    > or:
    >
    > disown %1 && logout[/ref]

    or, using zsh:

    /processFiles.rb &!

    everybody else was doing it, I felt left out :)

    - Mark



    Mark Guest

  6. #6

    Default Re: shell scripts in background (with &) - why would they stop?

    Hi,

    At Fri, 6 Feb 2004 01:41:42 +0900,
    Thomas Adam wrote in [ruby-talk:91620]: 

    Just
    disown -a

    --
    Nobu Nakada


    nobu.nokada@softhome.net Guest

Similar Threads

  1. shell scripts and cron
    By TB in forum Linux / Unix Administration
    Replies: 2
    Last Post: February 7th, 05:10 AM
  2. Systems administration shell scripts
    By gg.2.starfire@spamgourmet.com in forum Linux / Unix Administration
    Replies: 0
    Last Post: December 2nd, 08:30 PM
  3. [ANN] Protect you Unix Shell Scripts!
    By Bungisoft, Inc. in forum Linux / Unix Administration
    Replies: 3
    Last Post: November 9th, 02:43 PM
  4. Timers in shell scripts
    By Chris in forum Mac Programming
    Replies: 3
    Last Post: November 7th, 07:28 PM
  5. SHAREWARE - Unix shell scripts
    By RayCosoft in forum Linux / Unix Administration
    Replies: 0
    Last Post: November 3rd, 06:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139