1

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"
  • One question per question. I removed the question concerning reindexing, which you can ask it in a separate question. That said, the commands you've shown are shell commands, so why use Automator when a bash script in Terminal will do? – user3439894 Nov 15 '17 at 19:22
  • I don't know bash script. If anyone can write this up in bash I would be grateful. I inherited this Mac server and am still learning. – Tim Moseley Nov 16 '17 at 13:25
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .