Posted on 02-08-2023 04:42 AM
Hi all,
I will like the help some help in getting Extension Attributes up to grep SSHD.
/bin/launchctl print-disabled system | grep sshd
com.openssh.sshd => true
Sorry that scripting is new to me.
So the <result>True<result/> or False. Please help.
Solved! Go to Solution.
02-08-2023 05:26 AM - edited 02-08-2023 06:06 AM
@yuenhongtang If you want True when sshd is enabled, and False when not this will do it:
#!/bin/sh
# EA to check status for com.openssh.sshd
# Returns True if enabled
# False if disabled
sshdStatus=$(/bin/launchctl print-disabled system | /usr/bin/grep sshd | /usr/bin/grep enabled)
if [ -n "$sshdStatus" ]; then
result="True"
else
result="False"
fi
echo "<result>$result</false>"
02-08-2023 05:26 AM - edited 02-08-2023 06:06 AM
@yuenhongtang If you want True when sshd is enabled, and False when not this will do it:
#!/bin/sh
# EA to check status for com.openssh.sshd
# Returns True if enabled
# False if disabled
sshdStatus=$(/bin/launchctl print-disabled system | /usr/bin/grep sshd | /usr/bin/grep enabled)
if [ -n "$sshdStatus" ]; then
result="True"
else
result="False"
fi
echo "<result>$result</false>"
Posted on 02-08-2023 05:52 AM
Hi, I tried but result false or true. it returned True.
Posted on 02-08-2023 06:06 AM
@yuenhongtang Apologies, there was a typo in my original post. Please try the EA script now.
Posted on 02-08-2023 06:04 AM
Posted on 02-08-2023 06:22 AM
@yuenhongtang You don't want to have extraneous echo command in an EA. The script in my original post has been corrected, and now returns False when appropriate.
Posted on 02-08-2023 11:33 AM
Wouldn't running /usr/sbin/systemsetup -getremotelogin | /usr/bin/awk '{print $NF}' get the same results and possibly be easier? Not that there's any real problem with using launchctl print-disabled system. Just sort of thinking out loud.