Terminal commands in Automator for Profile Manager maintenance
-
18-04-2021 - |
Question
I am using macOS Server to manage our iPads and the Profile Manager is constantly having problems requiring me to stop the service and reboot the server. I also clean out the completed and non-completed tasks (this sometimes helps). I would like to use Automator to run a daily task to clear the completed tasks from the database and one to clear the non-completed tasks weekly.
Here is the code I have, can someone help me configure this for Automator?
Clear completed tasks:
sudo -u _devicemgr psql -U _devicemgr -d devicemgr_v2m0 -h /Library/Server/ProfileManager/Config/var/PostgreSQL -c "DELETE FROM library_item_tasks WHERE completed_at IS NOT NULL"
Clear non-completed:
sudo -u _devicemgr psql -U _devicemgr -d devicemgr_v2m0 -h /Library/Server/ProfileManager/Config/var/PostgreSQL -c "DELETE FROM library_item_tasks WHERE completed_at IS NULL"
Solution
Google: bash script how to - A bash
script is nothing more then a plain text file that starts with the appropriate shebang
and has the commands you want to execute, one line at at time. Then made executable with chmod
and if not placed in a directory in the PATH
use ./filename
to execute it.
The ./filename
method requires it in the PWD
in Terminal, otherwise use the fully qualified pathname. Placing it in a directory in the PATH
is typically easiest to then subsequently execute as needed just by filename
.
Example:
In Terminal:
touch cleartasks
open cleartasks
Add to opened file:
#!/bin/bash
sudo -u _devicemgr psql -U _devicemgr -d devicemgr_v2m0 -h /Library/Server/ProfileManager/Config/var/PostgreSQL -c "DELETE FROM library_item_tasks WHERE completed_at IS NOT NULL"
sudo -u _devicemgr psql -U _devicemgr -d devicemgr_v2m0 -h /Library/Server/ProfileManager/Config/var/PostgreSQL -c "DELETE FROM library_item_tasks WHERE completed_at IS NULL"
Save the file.
Back in Terminal, make it executable:
chmod u+x cleartasks
To execute:
./cleartasks