Path to place scripts for cronjobs

I’m planning to create a set of scripts to perform some cleanup tasks in the server, like using doveadm expunge to remove old emails.

In what path should I place those scripts?
Should I place those scripts in /home/admin and then create cronjobs from HestiaCP in the admin user?

Should I give those scrips any special owner or permissions (chown +x is obvious)

Thank you in advance.

You can use the dir you want, /home/admin/bin/, /usr/local/bin/, etc. but if those scripts must be run as root instead of admin, i. e. you must use sudo to run those scripts, then the scripts must be located here /usr/local/hestia/bin/

That’s because user admin is only allowed to use sudo with scripts located in that dir:

$ cat /etc/sudoers.d/admin
# Created by hestia installer
Defaults env_keep="VESTA"
Defaults env_keep+="HESTIA"
Defaults:admin !syslog
Defaults:admin !requiretty
Defaults:root !requiretty

# sudo is limited to hestia scripts
admin   ALL=NOPASSWD:/usr/local/vesta/bin/*
admin   ALL=NOPASSWD:/usr/local/hestia/bin/*
1 Like

Probally the best location is in the /root/ folder and call it then.

1 Like

Is it possible to run a cronjob from the admin user like the following or does it require special permissions?
doveadm -v expunge -u [email protected] mailbox Junk before 30d

If you want to use doveadm to manipulate user’s mailboxes, then you must be root and to do so using admin user you should create a script with those doveadm commands and put the script in /usr/local/hestia/bin/ then you can call it from admin’s cron job using sudo /usr/local/hestia/bin/YourScript

You can always create the cron jobs directly under user root but that will be out of Hestia’s scope.