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.

run a script after UPCP

Discussion in 'General Discussion' started by CoolMike, Aug 24, 2004.

  1. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Hi

    Is there a possibility to run a script right after the nightly upcp is finished?

    Right now I have a cron job, but sometimes the upcp takes longer sometimes not.

    Thanks
    Michael
     
  2. haze

    haze Well-Known Member

    Joined:
    Dec 21, 2001
    Messages:
    1,550
    Likes Received:
    3
    Trophy Points:
    38
    If you create a file in /scripts named postupcp ( no caps ) then cpanel will run whatever is in this file when upcp finishes.
     
  3. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    In the upcp script is:

    Code:
    if (-e "/scripts/postupcp") {
       system("/scripts/postupcp");
    }
    
    If a script called postupcp exists in the /scripts directory, it will automatically be run after upcp. All you need to do is name your script postupcp and put it in the /scripts directory and it will do what you want.
     
  4. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Haze beat me to it, but I gave an explanation. ;)
     
  5. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Wow, great, that was exactly what I need. But I'm just wondering, how did you find out about this? Is there a documentation about this, or did you just open the upcp script and found this?

    Thanks a lot!

    Mike
     
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I've studied most of the scripts. Makes it easier to write my own custom scripts to work with them. ;)
     
  7. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Hi

    I renamed now my script to postupcp and moved it to the script folder. When I run it, it works. But when I runt the upcp script, it will not be executed.

    What could be the reason?

    Thanks
    Michael
     
  8. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Or is there an other solution? I want to run this script as soon the nightly cpbackup is finished.

    Thanks
    Michael
     
  9. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Did you rename it to postupcp with or without an extension? It has to be called just "postupcp", no extension.
     
  10. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Also,

    1. You need to make it executable:

    chmod +x /scripts/postupcp

    2. You need to have a shell of some sort as the first line of /scripts/postupcp , for example:

    #!/bin/sh

    or for a perl script:

    #!/usr/bin/perl
     
  11. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    I did all this already and if I run the postupcp script manually, then it works. It even works, when I run the ./upcp Script manually, but it doesn't work, when in the nightly cronjob:

    35 1 * * * /scripts/upcp

    I just saw, that the postupcp is not really at the end of upcp. Could it be, that upcp stopps somewhere in the middle? Will the postupcp run before or after the backup? Because I need to run it definitly after the backup.

    Thanks
    Michael
     
  12. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Sounds like in the auto mode it's not getting that far, but it should.

    If you want to modify the backup script, you can have it call your script.

    Open the /scripts/cpbackup file and put:

    Code:
    if (-e "/scripts/postupcp") {
       system("/scripts/postupcp");
    }
    
    just before:
    Code:
    sub isolderthen {
    
    if you have backup enabled.

    If backup is not enabled, you will have to put it just before:
    Code:
    if ($CONF{'BACKUPENABLE'} ne "yes") {
    
    but you will need to change that if you enable backup later.


    You can change the /scripts/postupcp that you add if you want to put your script elsewhere, or give it a different name.
     
  13. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    An alternative, which I've used in the past, is to modify the root crontab so that it runs another command after upcp:

    /scripts/upcp ; /scripts/postupcp
     
  14. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    See, that's my problem. I like playing with scripts so much that I don't even think of the easy way. ;)
     
  15. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    CoolMike, (nice name btw) ;)

    If you do modify the crontab, you probably will want to change the script or path because if you call it postupcp it might end up getting run twice, by the cpanel call, (supposed to anyway), then by the cronjob call.
     
  16. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Great, this works now perfectly. Thanks a lot to all of you.

    squirrel, the name is already very old. I used it when I was in a chat the first time. :) Maybe 15 years ago, and did never change it againg.
     
Loading...

Share This Page