Running Linux or Mac Inventory Analyzers from a Windows Share

In many cases it may be easier to run the Linux or Mac Inventory Analyzer directly from a Windows share to avoid configuring the analyzer locally and managing inventory analyzer versions from a decentralized location.

Running the Linux Inventory Analyzer from a Windows Share

The following sample script will connect to a Windows file share using the SMB protocol, run the Linux Inventory Analyzer from that share, and automatically save the .adt file in the proper location.

This sample script requires the following:

  • A SMB client (Samba) is installed on Linux machines;
  • A shared folder is configured on a Windows machine;
  • The script is run with root privileges.

The script mount the share using the SMB protocol, run the Linux Inventory Analyzer, and then unmount the share.

IMPORTANT: Before running the script you must replace the script variables such as SHARENAME, USERNAME, PASSWORD, and MOUNTPOINT.

Bourne shell compatible script
# !/bin/sh
# Script for running lina from a Windows share
 
# Change these variables to match your environment
SHARENAME="//<auditserver>/<auditshare>"
USERNAME="<username>"
PASSWORD="<password>"
MOUNTPOINT="/mnt/ina"
 
ROOT_UID=0 # Only users with $UID 0 have root privileges
E_NOTROOT=67 # Non-root exit error
 
# Check if the script runs with root privileges
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script"
exit $E_NOTROOT
fi
 
# Connect to the Windows Share
echo "Connecting to the Windows share"
mkdir $MOUNTPOINT
chmod 777 $MOUNTPOINT
 
# For the most of Linux distributions
mount -t cifs -o username=$USERNAME,password=$PASSWORD $SHARENAME $MOUNTPOINT
 
# Uncomment if the mount.cifs helper is available
# Make sure the PATH environment variable contains
# the mount.cifs directory (typically, /sbin)
# mount.cifs $SHARENAME $MOUNTPOINT -o username=$USERNAME,password=$PASSWORD
 
# Uncomment for older Linux distributions
# (such as Red Hat Enterprise 4 and earlier and Debian 3 and earlier)
# mount -t smbfs -o username=$USERNAME,password=$PASSWORD $SHARENAME $MOUNTPOIN
 
# Run Linux Inventory Analyzer
echo "Running Linux Inventory Analyzer"
cd $MOUNTPOINT
$MOUNTPOINT/lina
 
# Unmount the $MOUNTPOINT share
echo "Unmounting the $MOUNTPOINT share"
cd /
umount $MOUNTPOINT
 
# Delete the temporary files
echo "Deleting the temporary files"
rmdir $MOUNTPOINT
echo "All done"
 
exit
Running the Script Under the Current User

Because the above script runs under the root account, the computer owner in the snapshot will be set to root. In order to avoid this, you can modify the script and run it under the current user. However, the Linux Inventory Analyzer will not be able to collect SMBIOS hardware information on the Linux computer. Additionally, non-privileged (non-root) users may be unable to mount Windows shares with the default settings in place.

To modify the script for running under the current user, delete the "Check if the script runs with root privileges" script section or add the hash symbol (#) to the beginning of every line in this section as follows:

# Check if the script runs with root privileges
#if [ "$UID" -ne "$ROOT_UID" ]
#then
#echo "Must be root to run this script"
#exit $E_NOTROOT
#fi

IMPORTANT: The current user must have sufficient permissions to mount a share. For instructions, see Mounting a Windows Share to Linux as a non-root user at https://www.techrepublic.com/article/how-to-permanently-mount-a-windows-share-on-linux.

Running the Mac Inventory Analyzer from a Windows share

The following sample script will connect to a Windows file share using the SMB protocol, run the Mac Inventory Analyzer from that share, and automatically save the .adt file in the proper location.

This sample script requires the following:

  • A SMB client (Samba) is installed on Mac machines;
  • A shared folder is configured on a Windows machine;
  • The script is run with root privileges.

The script will mount the share using the SMB protocol, run the Mac Inventory Analyzer, and then unmount the share.

NOTE: The script has been tested on Mac OS X 10.7. More recent macOS versions may require some adjustments.

IMPORTANT: Before running the script you must replace the script variables such as SHARENAME, USERNAME, PASSWORD, and MOUNTPOINT.

Bash shell script
#! /bin/bash
# Script for running ina_mac from a Windows share (on Mac OS X 10.7)
 
# Change these variables to match your environment
SHARENAME="<auditserver>/<auditshare>"
USERNAME="<userid>"
PASSWORD="<password>"
MOUNTPOINT="/mnt/ina"
 
ROOT_UID=0 # Only users with $UID 0 have root privileges
E_NOTROOT=67 # Non-root exit error
 
# Check if the script runs with root privileges
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script"
exit $E_NOTROOT
fi
 
# Connect to the Windows Share
echo "Connecting to the Windows share">
mkdir /mnt
mkdir $MOUNTPOINT
chmod 777 $MOUNTPOINT
mount -t smbfs //$USERNAME:$PASSWORD@$SHARENAME $MOUNTPOINT
 
# Run Mac Inventory Analyzer
echo "Running Mac Inventory Analyzer"
cd $MOUNTPOINT
$MOUNTPOINT/ina_mac -v
 
# Unmount the $MOUNTPOINT share
echo "Unmounting the $MOUNTPOINT share"
cd /
umount $MOUNTPOINT
 
# Delete the temporary files
echo "Deleting the temporary files"
rmdir $MOUNTPOINT
echo "All done"
 
exit
Running the Script Under the Current User

Because the above script runs under the root account, the computer owner in the snapshot will be set to root. In order to avoid this, you can modify the script and run it under the current user. However, non-privileged (non-root) users may be unable to mount Windows shares with the default settings in place.

To modify the script for running under the current user, delete the "Check if the script runs with root privileges" script section or add the hash symbol (#) to the beginning of every line in this section as follows:

# Check if the script runs with root privileges
 
#if [ "$UID" -ne "$ROOT_UID" ]
#then
#echo "Must be root to run this script"
#exit $E_NOTROOT
#fi

IMPORTANT: The current user must have sufficient permissions to mount a Windows share. For instructions, see Mounting a Windows Share to Linux as a non-root user at https://www.techrepublic.com/article/how-to-permanently-mount-a-windows-share-on-linux.