LUG.sh
Write Local User and Groups data to LANDesk inventory file
Carregue aqui para obter o ficheiro
Conteúdo do ficheiro
#!/bin/sh
# #############################################################################
NAME_="LUG.sh"
PURPOSE_="Write Local User and Groups data to LANDesk inventory file"
REQUIRES_="defaults, dscl"
VERSION_="1.04"
DATE_="2008-01-28"
AUTHOR_="Gil Burns <gil.burns@aquantive.com>"
CATEGORY_="LANDesk"
PLATFORM_="Mac OS X"
SHELL_="bash"
DISTRIBUTE_="yes"
NOTES_="fixed group names with leading white space"
# #############################################################################
# commands
dsclCommand="/usr/bin/dscl"
defaultsCommand="/usr/bin/defaults"
# data files
plistFile="/Library/Application Support/LANDesk/data/ldscan.core.data"
# #############################################################################
userDetails()
{
userList=`${dsclCommand} . list /Users`
for userName in $userList
do
userNameRealName=`${dsclCommand} . read /Users/$userName RealName | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
userNameUID=`${dsclCommand} . read /Users/$userName UniqueID | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
userNamePrimaryGroupID=`${dsclCommand} . read /Users/$userName PrimaryGroupID | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
userNamePassword=`${dsclCommand} . read /Users/$userName Password | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
userNameUserShell=`${dsclCommand} . read /Users/$userName UserShell | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
userNameNFSHomeDirectory=`${dsclCommand} . read /Users/$userName NFSHomeDirectory | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
if [[ "$userNameUID" -lt 999 ]] ; then
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - Name" "$userName"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - Full Name" "$userNameRealName"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - UID" "$userNameUID"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - GID" "$userNamePrimaryGroupID"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - Password" "$userNamePassword"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - Shell" "$userNameUserShell"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local User Accounts - $userName - Home" "$userNameNFSHomeDirectory"
fi
done
}
groupDetails()
{
groupList=`${dsclCommand} . list /Groups`
for groupName in $groupList
do
groupNameRealName=`${dsclCommand} . read /Groups/$groupName RealName | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
groupNameGroupMembership=`${dsclCommand} . read /Groups/$groupName GroupMembership | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
groupNamePrimaryGroupID=`${dsclCommand} . read /Groups/$groupName PrimaryGroupID | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
groupNamePassword=`${dsclCommand} . read /Groups/$groupName Password | cut -d : -f 2 | sed 's/^[ \t]*//' | sed '/./,$!d'`
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local Groups - $groupNameRealName - Short Name" "$groupName"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local Groups - $groupNameRealName - Name" "$groupNameRealName"
if [ "$groupNameGroupMembership" != "GroupMembership" ] ; then
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local Groups - $groupNameRealName - Members" "$groupNameGroupMembership"
fi
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local Groups - $groupNameRealName - GID" "$groupNamePrimaryGroupID"
${defaultsCommand} write "$plistFile" "Local Users and Groups - Local Groups - $groupNameRealName - Password" "$groupNamePassword"
done
}
userDetails
groupDetails
# fix permissions to make the file readable by all
chown root:admin /Library/Application\ Support/LANDesk/data/ldscan.core.data.plist
chmod 644 /Library/Application\ Support/LANDesk/data/ldscan.core.data.plist
exit 0