Posted on 04-04-2022 10:27 AM
Hello everyone
I'm using execute command option in the Files and processes payload of a policy and want to run a small script ( 5 lines), I'm using a simple if statement to check whether a folder exists or not and create it, I'm getting a syntax error on the test client when I run it from Jamf however I tested and it works fine if I run it as a script from terminal so this issue is possibly the way I'm using semicolon, this could be done using script payload but I need to make it work this way.
This is working as a script
if [ ! -d "Path/to/location" ]
then
mkdir Path/to/location
Sleep 2
touch Path/to/location/hello.plist
else
touch Path/to/location/hello.plist
fi
This is how I added it to files and processes payload
if [ ! -d "Path/to/location/" ] ; then ; mkdir Path/to/location/ ; sleep 2 ; touch /Path/to/location/hello.plist ; else ; touch Path/to/location/hello.plist ;
Solved! Go to Solution.
Posted on 04-04-2022 10:55 AM
The mkdir command has an option to create directories if they don't exist.
Try this instead of using an if statement: mkdir -p Path/to/location
Posted on 04-04-2022 10:36 AM
In my opinion, anything longer than one or maybe two lines should be done as a dedicated script.
04-04-2022 10:39 AM - edited 04-04-2022 11:07 AM
@OMP I'm curious, why won't running this via a Script payload work? I am in the same camp as @andrew_nicholas when it comes to dedicated scripts as the maintainability of multi line commands in a Files and Processes payload is non-optimal (you can read that as it sucks).
04-04-2022 10:54 AM - edited 04-04-2022 10:56 AM
You are missing the closing fi. Also watch out for missing leading slashes in your paths... 🙂
if ! [ -d "Path/to/location/" ]; then; mkdir Path/to/location/; sleep 2; touch /Path/to/location/hello.plist; else; touch Path/to/location/hello.plist; fi
Posted on 04-04-2022 10:55 AM
The mkdir command has an option to create directories if they don't exist.
Try this instead of using an if statement: mkdir -p Path/to/location
Posted on 04-04-2022 11:00 AM
Thank you all for your helpful contributions, checking now