Adding JAMF Variables to script

BD_SU
New Contributor

I am trying to add JAMF script variables to my script, the scripts function is to check user home folders and if it had not been modified in an X amount of days it will delete the folder. I want to be able to change the amount of days depending on the deployment location. Would I simply just need to add $4 to the area where the variable would be input?

#!/bin/bash

# Set the number of days to 90
days=90 (<----- This would just change to days=$4, then in JAMF I would set the amount of days in the first variable section. 

# Set the excluded users
excluded_users=("macadmin" "shared" "Shared" "admin")

# Get current date in seconds
now=$(date +%s)

# Iterate over all users home folder
for dir in /Users/*; do
# Check if the folder is a directory and not one of the excluded users
if [ -d "$dir" ] && [[ ! " ${excluded_users[@]} " =~ " $(basename "$dir") " ]]; then
# Get the last modified date of the folder
last_modified=$(stat -f "%m" "$dir")
# Calculate the difference between the last modified date and the current date
diff=$(((now - last_modified) / 86400))
# If the difference is greater than X days, delete the folder
if [ $diff -gt $days ]; then
sudo rm -rf "$dir"
fi
fi
done
1 ACCEPTED SOLUTION

jamf-42
Valued Contributor II

yes.. $4 will be the value you set. note script runs as root. 'sudo' rm not needed.. 

make sure you tag this in the script Parameter Labels, then it will be shown in the script variables in the policy 

View solution in original post

2 REPLIES 2

jamf-42
Valued Contributor II

yes.. $4 will be the value you set. note script runs as root. 'sudo' rm not needed.. 

make sure you tag this in the script Parameter Labels, then it will be shown in the script variables in the policy 

BD_SU
New Contributor

Awesome, thank you.