-
Notifications
You must be signed in to change notification settings - Fork 13
/
OneDrive_Process_Health.sh
42 lines (36 loc) · 1.02 KB
/
OneDrive_Process_Health.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/zsh
## Extension Attribute to report whether the OneDrive process is configured and running
GetLoggedInUser() {
LOGGEDIN=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/&&!/loginwindow/{print $3}')
if [ "$LOGGEDIN" = "" ]; then
echo "$USER"
else
echo "$LOGGEDIN"
fi
}
SetHomeFolder() {
HOME=$(dscl . read /Users/"$1" NFSHomeDirectory | cut -d ':' -f2 | cut -d ' ' -f2)
if [ "$HOME" = "" ]; then
if [ -d "/Users/$1" ]; then
HOME="/Users/$1"
else
HOME=$(eval echo "~$1")
fi
fi
}
## Main
LoggedInUser=$(GetLoggedInUser)
SetHomeFolder "$LoggedInUser"
# Find out if OneDrive is configured
DataFile=$(ls -t $HOME/Library/Application\ Support/OneDrive/settings/Business1/*dat | head -n 1)
if [ "$DataFile" != "" ]; then
OneDriveProcessId=$(/usr/bin/sudo -u $LoggedInUser /usr/bin/pgrep 'OneDrive')
if [ "$OneDriveProcessId" != "" ]; then
echo "<result>Running</result>"
else
echo "<result>Not running</result>"
fi
else
echo "<result>Not configured</result>"
fi
exit 0