JAMF auto delete download folder

TDManila
New Contributor III

Hello - Happy New Year! I have been looking for a script of "auto delete files once the device has restarted" 

I found this script but it seems not to be working.. 

 

Expand
# Fetch the target user if desired, otherwise use the currently logged in user.
if [ "$4" != "" ]; then
    TargetUser=$4
else
    TargetUser=$3
fi
echo "Target user is $TargetUser."

# Delete common user spaces of the targetted user.
rm -Rf /Users/$TargetUser/Desktop/*
rm -Rf /Users/$TargetUser/Documents/*
rm -Rf /Users/$TargetUser/Downloads/*
rm -Rf /Users/$TargetUser/Applications/*
rm -Rf /Users/$TargetUser/.Trash/*

exit 0  
6 REPLIES 6

robjschroeder
Contributor

Hey! What’s the use case here? Would a guest account be sufficient? 
If it’s a shared computer situation, why not just delete all inactive user profiles after “x” amount of days? 

Hello bro! We want to implement the auto delete  download files on ALL accounts regardless if it's admin. just like the "deepfreeze" thing on windows. So as long as the device restarted, the download files should be deleted.

Probably looking for more of a launch daemon then that you can have run after a reboot

karthikeyan_mac
Valued Contributor

@TDManila Its recommended to follow @robjschroeder suggestion.

How are you running the script? Login trigger? what does the policy logs show?

Thanks.

 

robjschroeder
Contributor

Something like: 

DAYS=$4

find /Users -type d -mtime +"$DAYS" -maxdepth 1 -not -path "/Users" -not -path "/Users/admin" -not -path "/Users/Shared" -exec rm -r "{}" \;

And then just have a policy run this on a recurring check-in at whatever frequency you would like or works for you.