Update the disk usage for a User after they upload or delete a file through the DA File Manager


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin » Custom Scripting

Update the disk usage for a User after they upload or delete a file through the DA File ManagerLast Modified: Feb 24, 2016, 1:07 am
If you'd like to run a mini "quotatally" for a given User if they upload or delete a file through the DA FileManager, you can use the script:
filemanager_pre.sh
to accomplish this.

For file deletion, we'd need to check for:

action=multiple
button=delete


and for uploads, we'd need to check for:

action=upload


NOTE: requires binaries compiled on after Feb 24th, 2016, or else the $username variable will be blank.

So create the script:

/usr/local/directadmin/scripts/custom/filemanager_pre.sh

and add the code:

#!/bin/sh
DO_TALLY=0

if [ "$username" = "" ]; then
   echo "Username is blank. Ensure you have DA binaries compiled after Feb 24th, 2016";
   exit 1;
fi

if [ "$action" = "multiple" ] && [ "$button" = "delete" ]; then
   DO_TALLY=1
fi

if [ "$action" = "upload" ]; then
   DO_TALLY=1
fi

if [ "$DO_TALLY" -eq 1 ]; then
   echo "action=quotatally&value=${username}&type=user" >> /usr/local/directadmin/data/task.queue
fi

exit 0;

and chmod the script to 755, eg:

chmod 755 /usr/local/directadmin/scripts/custom/filemanager_pre.sh



Keep in mind that we're using a "pre" script, meaning it's run before the actual action takes place.
This is because the File Manager cannot have a post.sh script due to the fact it's chrooted by the end of the action.
The implications of issuing the task.queue command before the action has taken place is that there is a very small chance that the disk usage could be updated before the action is finished, so the disk usage might actually be the old value, before the file was added/deleted.   However, the odds of this race condition actually being true is very low.  Uploaded files are already in /home/tmp before the action is done, so it only requires a rename (very fast), and deletions are also very fast, so they'll most likely beat the completion of the disk usage update.  This condition also requires that the dataskq is called by cron at the exact moment of the upload/deletion, so that's lowers the odds even more.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST