Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Member
    Join Date
    Nov 2008
    Posts
    16

    Question Running Bash Script when ...

    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. #2
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Running Bash Script when ...

    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):

    error_log:[2011-04-25 14:02:09 -0400] info [parkadmin] Creating Addon domain 'addondomain.com' on 'addondomain.maindomain.com'.
    This does not occur for parked and subdomain creation or termination.

    If you enable the following in WHM > Tweak Settings:

    Log dnsadmin requests [?]

    Log dnsadmin requests to /usr/local/cpanel/logs/dnsadmin.log
    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
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  3. #3
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    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. #4
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Running Bash Script when ...

    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.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  5. #5
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    jdhf99 at his thread confirm the addon and park hooks
    http://forums.cpanel.net/f42/cpanel-...ks-125393.html

    thank you Tristan for your confirm, I am going to have a test. and I'll update this thread later

  6. #6
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    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. #7
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: Running Bash Script when ...

    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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  8. #8
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    Yes David, I am deleting the account first before I am restoring it.
    Okay David, understood.

    And case closed.

  9. #9
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    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-cp...-a-194431.html

    Hook:
    We have now added a “modifyacct” hook at /usr/local/cpanel/scripts/postmodifyacct and /usr/local/cpanel/scripts/premodifyacct. It will be passed all the new values for an account.
    ps: I am using latest stable cpanel ver 11.28.xx

  10. #10
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: Running Bash Script when ...

    Hi pakogah,

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

    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  11. #11
    Member
    Join Date
    Nov 2008
    Posts
    16

    Default Re: Running Bash Script when ...

    oke thank you David

Similar Threads & Tags
Similar threads

  1. Run Bash Script /
    By Spiral in forum cPanel Developers
    Replies: 6
    Last Post: 06-28-2010, 09:28 AM
  2. running Bash file?
    By CJL in forum New User Questions
    Replies: 1
    Last Post: 12-03-2009, 05:52 AM
  3. Bash script
    By merlinpa1969 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 08-05-2007, 01:33 PM
  4. user nobody running bash and inetd
    By CamronFry in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 04-07-2005, 03:56 PM
  5. PHP Running BASH
    By Etheral in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 07-11-2004, 04:22 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube