• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Event Manager and script

M

MaRiOs

Guest
I use the Event manager ,and
add an Event handler.

The hander is about Domain Creation
and it is supposed to create a folder .ssh every time a new domain is added.The command it runs is :

/usr/local/psa/bin/ssh.sh <new_domain_name>

the ssh.sh script contains :

#!/bin/bash
echo "--------------" >> /tmp/event_handler.log
/bin/date >> /tmp/event_handler.log
/usr/bin/id >> /tmp/event_handler.log
cd /home/httpd/vhosts/$1 >> /tmp/event_handler.log
pwd >> /tmp/event_handler.log
if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi >> /tmp/event_handler.log
#mkdir .ssh >> /tmp/event_handler.log
echo "domain: $1" >> /tmp/event_handler.log # domain name`cat authorized_keys`
echo "--------------" >> /tmp/event_handler.log
echo -e "Subject:New Domain Notification\nFrom:Server <[email protected]>\n"`cat /tmp/event_handler.log` | /usr/sbin/sendmail [email protected]

In the email i get result like :

Tue Aug 23 07:03:35 CEST 2005 uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) /root domain: sdgfadgfsadfgsdfgsd.gr --------------

the .ssh folder is not created in the target folder i wanted,so i gave the
pwd >> /tmp/event_handler.log in the script to see where it goes.
and it goes in the /root
I tried many things and i cant make it go to cd /home/httpd/vhosts/$1
any ideas ?
 
I emailed you. You have to set it up in Event Manager for 'Physical Hosting created', not 'Domain Created', or what happens is your script is run BEFORE the new domain directories are created.
 
dont be happy its not finished yet i have to add some more things,
im testing them now,
ill be back with questions lol
 
Understood and expected. That's what these forums are for!
 
Ok no questions for this part ;)

The final script looks like that :

#!/bin/bash
echo "--------------" >> /tmp/event_handler.log
/bin/date >> /tmp/event_handler.log # information on the event date and time
/usr/bin/id >> /tmp/event_handler.log # information on the user, on behalf of which the script was executed (to ensure control)
cd /home/httpd/vhosts/$1 >> /tmp/event_handler.log
pwd >> /tmp/event_handler.log
if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; chown $2 .ssh ; chgrp psaserv .ssh ; fi >> /tmp/event_handler.log
cd /home/httpd/vhosts/$1/cgi-bin >> /tmp/event_handler.log
if [ ! -d locked ]; then mkdir locked ; chmod 755 locked ; chown $2 locked ; chgrp psaserv locked ; fi >> /tmp/event_handler.log
echo "domain: $1" >> /tmp/event_handler.log # information on the created client account
echo "login: $2" >> /tmp/event_handler.log # information on the created client account
echo "--------------" >> /tmp/event_handler.log
echo -e "Subject:New Domain Notification\nFrom:Server <[email protected]>\n"`cat /tmp/event_handler.log` | /usr/sbin/sendmail [email protected]


I have added this <new_system_user>
in the handler and a new line in the script
so now it creates the .ssh folder gives it the chown chmod chgrp i want
and then do the same for the locked folder :)

mission accomplished.
 
Back
Top