Run Script as Logged in User - Collect Application Logs - Vectorworks

mcgace
New Contributor III

Hi guys,

I am trying to run a script as a Self Service policy that will collect Vectorworks log files from a Users machine and add it as an attachment in the device's inventory.

I found this script by Matt Taylor that is really good:
https://github.com/matt-taylor934/loguploader/blob/master/loguploader.sh

But I can't figure out how to get it to include the Vectorworks log file at this location: /Users/logged.in.user/Library/Application Support/Vectorworks/2019/VW User Log.txt

I added a variable for the location of the log file to the compressed zip $vwFileLocation but its not int he output:

bd8c0f1802ba438981c2505a3c4eed12

I guess it needs the logged in user? I don't know how to get the logged in user. Or does it need to run as the logged in user and how do I do that?

Scripting is very new to me so any help would be appreciated.

1 ACCEPTED SOLUTION

r___
New Contributor III

@mcgace

Lets try putting double quotes around your VW Log variable when calling it back in zip

## Compress the log files we're uploading and name it with a timestamp.
/usr/bin/zip -r -j $logArchive $jamfLog $installLog $systemLog "$vwUserLog"

View solution in original post

8 REPLIES 8

r___
New Contributor III

Try using this as the variable for logged in user

currentUser=$(ls -l /dev/console | awk '{ print $3 }')

Then you can call that variable back in your path

/Users/$currentUser/Library/Application Support/Vectorworks/2019/VW User Log.txt

mcgace
New Contributor III

@r... I tried that but no luck, still not working.

My Syntax:
## Get User Name.
currentUser=$(ls -l /dev/console | awk '{ print $3 }')
# Specify the log files being requested.
jamfLog="/var/log/jamf.log"
installLog="/var/log/install.log"
systemLog="/var/log/system.log"
vwUserLog="/Users/$currentUser/Library/Application Support/Vectorworks/2019/VW User Log.txt"
## Compress the log files we're uploading and name it with a timestamp.
/usr/bin/zip -r $logArchive $jamfLog $installLog $systemLog $vwUserLog

donmontalvo
Esteemed Contributor III

Might post entire script, don't see $logArchive (the zip archive being created) path being defined.

EDIT: Never mind I see you posted the GitHub URL to the script.

--
https://donmontalvo.com

r___
New Contributor III

@mcgace Are you getting any of those logs back when running this policy from self service?

mcgace
New Contributor III

@r... yes I get a zip file with the three log files (install.log, jamf.log system.log) but not the one I'm trying to get for Vectorworks

r___
New Contributor III

@mcgace

Lets try putting double quotes around your VW Log variable when calling it back in zip

## Compress the log files we're uploading and name it with a timestamp.
/usr/bin/zip -r -j $logArchive $jamfLog $installLog $systemLog "$vwUserLog"

mcgace
New Contributor III

@r... Thanks that worked. I now get an output like the one below.

580d3ed46c2b4f21be36a3ae0668b51d

What does double quotes around the variable mean?

r___
New Contributor III

@mcgace

The variable you were calling has spaces in the file name, the double quotes allow the variable to be called back with those spaces intact. I also included the -j switch so it would junk the directories and just keep the log files

Happy to read you're up and running