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.

Running Bash Script when ...

Discussion in 'cPanel Developers' started by pakogah, Apr 25, 2011.

  1. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Dear All,

    First of all I want to say Hi,
    This is my first thread on cPanel forum.

    Secondly I need your confirmation on:
    I want to collect information number of domain added/deleted on my cpanel server using bash script.

    From what I saw, domain get added or deleted when:
    - new account created / restored / deleted
    - addon domain created / deleted
    - park domain created / deleted

    I have search the net and manual for cpanel there are some function/script hooks that get invoked after above procedure run:

    /scripts/postrestoreacct
    /scripts/postwwwacct
    /scripts/postkillacct
    /usr/local/cpanel/hooks/addondomain/addaddondomain
    /usr/local/cpanel/hooks/addondomain/deladdondomain
    /usr/local/cpanel/hooks/park/park
    /usr/local/cpanel/hooks/park/unpark

    can I insert my bash script inside those hooks?
    or is there any easy way? perhaps cpanel has a log what domain get added/deleted?

    Thank you for your confirmation.
    Looking forward for answer
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    There is a log for domain creation and termination for primary domains at /var/cpanel/accounting.log location which would handle this option:

    - new account created / restored / deleted

    This log does not handle addon, subdomain or parked domain creation and termination. For addon domains, you will get those logged to the error_log with this format for creation (but not for termination):

    This does not occur for parked and subdomain creation or termination.

    If you enable the following in WHM > Tweak Settings:

    This will save a log of all zone creation and changes to /usr/local/cpanel/logs/dnsadmin_log location (of note, while the path is noted as dnsadmin.log, the actual file is called dnsadmin_log instead).

    Thus, if you are wanting to use logs to find these instead of using hooks, you can try the above logs. It would be easiest for main account creation, changes and termination to use the /var/cpanel/accounting.log and for addon domain creation to use /usr/local/cpanel/logs/error_log location
     
  3. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Thanks Tristan,
    but unfortunately I didn't enable dnsadmin log. I will enable now and see what the output.

    btw does list of the function / script hooks on my previous post is correct?
    that they will be invoked when:
    - new account created / restored / deleted
    - addon domain created / deleted
    - park domain created / deleted

    and can I insert my bash script inside those hooks?

    thanks b4
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Those appear to be the correct files based on the documentation I've found so far. I am familiar with the /scripts/ files you note, but I am not overly familiar with the hooks files for the parked and addon domains, so I'll let a developer confirm if the information is otherwise accurate for parked and addon domains.
     
  5. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
  6. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Okay I have tried it and here the result..

    first you make scripts/hooks above if not exist before.
    chmod +x the scripts/hooks so it's executable
    then add your own bash script.
    if you adding hooks: run /usr/local/cpanel/bin/register_hooks

    Code:
    # cat /scripts/postkillacct
    # calling my own script
    /root/scripts/hookcheck.sh AccountDeleted
    
    # cat /root/scripts/hookcheck.sh
    #!/bin/bash
    date >> /root/scripts/hookcheck.log
    echo $1 >> /root/scripts/hookcheck.log
    one things odd, is that when I am restoring a cpanel account, it calling /scripts/postwwwacct before then /scripts/postrestoreacct. here's from my log
    Code:
    Wed May  4 20:08:50 WIT 2011
    AccountCreated
    Wed May  4 20:08:59 WIT 2011
    AccountRestored
    ..just 9 second separated..
    WHY??
     
  7. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Was the account completely deleted from the system before you ran the restore process? If that is the case, what likely is happening is the restoration process is creating the account first (using normal, internal creation processes) and then applying the files present in the restore package. I would guess the delay is related to an Apache restart.

    -DavidN
     
  8. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Yes David, I am deleting the account first before I am restoring it.
    Okay David, understood.

    And case closed.
     
  9. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    I forgot, domain name also can be change on
    WHM >> Account Functions >> Modify an Account
    set by Primary Domain field.

    does anybody know what script/hook executed after Account Modification??
    or do I should wait until cpanel 11.30 ??
    http://forums.cpanel.net/f42/blog-cpanel-11-30-a-194431.html

    ps: I am using latest stable cpanel ver 11.28.xx
     
  10. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi pakogah,

    Yes, you will want the postmodifyacct hook. The postmodifyacct hook is only available in version 11.30 and beyond.

    Regards,
    -DavidN
     
  11. pakogah

    pakogah Member

    Joined:
    Nov 6, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    oke thank you David
     
Loading...

Share This Page