The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can someone post the code for running a script after your logoff

Discussion in 'General Discussion' started by DWHS.net, Jun 26, 2006.

  1. DWHS.net

    DWHS.net Well-Known Member
    PartnerNOC

    Joined:
    Jul 28, 2002
    Messages:
    1,569
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    LA, Costa RIca
    cPanel Access Level:
    Root Administrator
    I'm trying to keep a perl script running even when I logoff of the system.

    Yet it keeps dying when I log off.

    This is all done from the command line through root.

    Thanks! :)
     
  2. garrettp

    garrettp Well-Known Member
    PartnerNOC

    Joined:
    Jun 18, 2004
    Messages:
    312
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    DataCenter Provider
    You could try perhaps spawning a screen session before logging out and running the script from within that screen.
     
  3. bhd

    bhd Well-Known Member

    Joined:
    Sep 20, 2003
    Messages:
    149
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    JNB ZA
    cPanel Access Level:
    Root Administrator
    Not sure if this is what you mean but for most things, just add '&' after the command and the script will run in the background like so ./script.pl &
     
  4. garrettp

    garrettp Well-Known Member
    PartnerNOC

    Joined:
    Jun 18, 2004
    Messages:
    312
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    DataCenter Provider
    The problem with sending the process to the background is when you exit the shell anything spawned in that shell (be it in the background or otherwise) will be terminated.
     
  5. WEB-PROS

    WEB-PROS Well-Known Member

    Joined:
    Feb 19, 2006
    Messages:
    111
    Likes Received:
    0
    Trophy Points:
    16
    If im correct use "screen ****" then Cntrl A and Cntrl D and it will leave the screen and stay running even if you log off.
     
  6. jrehmer

    jrehmer Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    287
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Denver, CO
    Code:
    nohup /bin/somecommand &
    This will run the program in the background and prevent the hangup signal when logging off.
     
  7. nxds

    nxds Well-Known Member

    Joined:
    Jan 6, 2006
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    6
    On Bash and Zsh you can 'disown' processes so that they don't die when you exit the shell.

    For example :

    Code:
    % sleep 10000
    ctrl-Z                                                 # send stop signal
    [1]+  Stopped                 sleep 1000               # 1 is the job number
    % bg                                                   # put job in background
    [1]+ sleep 1000 &
    % disown %sleep                                        # or disown %1
    % exit
     
  8. WEB-PROS

    WEB-PROS Well-Known Member

    Joined:
    Feb 19, 2006
    Messages:
    111
    Likes Received:
    0
    Trophy Points:
    16
    Yes that is virtualy screening it, putting it the background and then be able to pull it back.
     
Loading...

Share This Page