Posted on 06-05-2017 02:49 PM
Hello,
Looking for help on my current bash script to reinstall the JSS management. Everything is working except I cant figure out how to search every line of the output to the command variable.
#!/bin/bash
jss_comm_chk=$(jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)
if [[ "$jss_comm_chk" == *"JSS is available"* ]]
then
echo "JSS binary already installed. Attempting to reinstall..."
sudo jamf removeFramework
sleep 2
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
sleep 2
fi
if [[ "$jss_comm_chk" == *"command not found"* ]] #FAILS TO SEARCH HERE
then
echo "JSS binary not currently installed. Attempting to install..."
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
fi
if [[ "$jss_comm_chk" == *"Waiting 5"* ]]
then
echo "No internet connection. Please connect to any network BESIDES CorpWifi."
fi
This is the output of the variable above where its failing:
[1] 71021
-bash: jamf: command not found
[1]+ Exit 127 jamf checkJSSConnection
-bash: kill: (71021) - No such process
1
Posted on 06-05-2017 03:05 PM
Have you tried using the full path to the jamf binary?
jss_comm_chk=$(/usr/local/jamf/bin/jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)
That should work for you.
Posted on 06-06-2017 02:50 AM
Hi,
using the full path name is always a good idea. But before using the jamf binary it might also be useful to check whether it exists (and is an executable:
if [ -x /usr/local/jamf/bin/jamf ]; then
# it exists, and it is executable, so I can use it :)
do nice things with /usr/local/jamf/bin/jamf
else
# it's not there, or it is not executable :(
echo "I am doomed"
fi
And before removing the existing framework I would check whether the QuickAdd package is indeed on the client. Would be a pity to remove the old framework if the package needed to re-install it is not there...
I have seen several clients on which /usr/local/jamf/bin/jamf did not exist due to some hiccup during the update :(
Hope this helps.
Posted on 06-06-2017 08:54 AM
Thank you guys that helps! @f.deis It doesn't work using full path but I will definitely use it to be safe. What I cant figure out is printing or searching the second line of the output. Thats where it fails. But using @mschroder tip works perfectly! New code below: Feedback welcome =)
#!/bin/bash
jss_comm_chk=$(/usr/local/jamf/bin/jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)
if [[ "$jss_comm_chk" == *"JSS is available"* ]]
then
echo "JSS binary already installed. Attempting to reinstall..."
sudo jamf removeFramework
sleep 2
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
sleep 2
fi
if [[ "$jss_comm_chk" == *"Waiting 5"* ]]
then
echo "No internet connection. Please connect to any network BESIDES CorpWireless."
fi
if [ -x /usr/local/jamf/bin/jamf ]
then
:
else
echo "JSS binary not currently installed. Attempting to install..."
fi
Posted on 06-07-2017 11:26 AM
Can anyone help with why I am unable to removeFramework when calling shell script from AppleScript droplet (.app)? It works fine when running from terminal.
Posted on 06-07-2017 01:33 PM
@yurypanasyuk - you looked at Casper Agent Check by Rich Trouton? It's well documented and achieves what you want
Posted on 06-08-2017 07:44 AM
Yes I have seen it but it still doesnt solve but I am trying to do. To simplify I tested using AppleScript code below and it errors out with:
"/bin/sh: usr/sbin/jamf: No such file or directory". Running directly from terminal has no issues.
AppleScript:
do shell script "usr/sbin/jamf removeFramework" with administrator privileges
Posted on 06-08-2017 07:57 AM
@yurypanasyuk -
#!/bin/sh
#Run System Command to Remove JAMF Framework
sudo /usr/local/bin/jamf removeFramework
Posted on 06-08-2017 07:58 AM
@yurypanasyuk -
#!/bin/sh
#Run System Command to Remove JAMF Framework
sudo /usr/local/bin/jamf removeFramework