• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Question Disable domains when running CRON

ruben_0129

New Pleskian
Hello,

I have Plesk Onyx on Ubuntu 16

I run a CRON to optimize and repair the database every day.

I wish that when this CRON is run the domains will be deactivated.

Is there any way to do it?

A greeting.
 
You could run command like:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --off $i; done

at the beginning of your cron script and:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --on $i; done

at the end of script.
 
That's not enough.
You need to also "remember" these domains that were disabled before starting the job or else you're gonna enable those afterward as well.
 
You could run command like:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --off $i; done

at the beginning of your cron script and:

# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select name from domains"`; do /usr/local/psa/bin/domain --on $i; done

at the end of script.

Could this command be executed with a -all?

It would be all domains. (29)

Thanks!
 
Yes, these commands will disable/enable ALL domains. But you can use appropriate mysql select for necessary conditions there.
 
This approach would not enable all the domains of your server and preserve the ones that were already set inactive.

It would only act upon the domains that are active.
It therefore preserves the state of your server before it executed the script.

Code:
#!/bin/bash

TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`

mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -Ns -e "select name from domains where status=0" 2>/dev/null >${TMPDIR}/domains

while read DOMAIN ; do
  /usr/local/psa/bin/domain --off ${DOMAIN}
done <${TMPDIR}/domains

echo "Do your thing"

while read DOMAIN ; do
  /usr/local/psa/bin/domain --on ${DOMAIN}
done <${TMPDIR}/domains

rm -r ${TMPDIR}
 
Back
Top