Skip to main content
Solved

Adding JAMF Variables to script


Forum|alt.badge.img+2
  • New Contributor
  • 1 reply

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

Best answer by jamf-42

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 original
Did this topic help you find an answer to your question?

2 replies

jamf-42
Forum|alt.badge.img+17
  • Esteemed Contributor
  • 741 replies
  • Answer
  • May 11, 2023

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 


Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • May 11, 2023
jamf-42 wrote:

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 


Awesome, thank you. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings