Terminal commands in Automator for Profile Manager maintenance
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