Jump to content
Tampait

OSX Scripts and Tips

Recommended Posts

I do not see a thread with anything focused on OSX Agents, we are looking to find resources, scripts, and tips for using LT to manage OSX devices.

Share this post


Link to post
Share on other sites

How about this?

 

The LabTech script function "Execute Script" only supports Windows. The "Text File Write" function preserves Windows cr/lf codes, so if you try and write a shell script and execute it the cr/lf characters will give you grief. LabTech will suggest that you pre-create your scripts in your LTShare and then download them. And if you successfully execute a script your output will only have line-feeds and trying to use it with the Script Log function or others will not display correctly.

 

This is how I work around those problems so that I can execute scripts on the fly:

1: Define a temporary filename. I use a Variable Set = SQL Query to generate a unique name: TempScriptPath = SQL QUERY SELECT CONCAT('/tmp/lt',SUBSTRING(CONCAT(ROUND(10000.0 + 9999.0 * RAND()),DATE_FORMAT(NOW(),'-%Y%m%d%H%i%s')),2),'.sh') AS uniquefilename;

The result will be something like: "/tmp/lt7479-20170207152450.sh" (Pretty sure that is safely unique...)

2: Use the "File Write Text" function, saving to "@TempScriptPath@". You can do variable substitution so the script can have customized code, and don't worry about cr/lf, you can work right within the function editor box.

3: Use the "Process Execute" function, and execute process "tr", with parameters "-d '\r' < '@TempScriptPath@' | /bin/sh | sed -e 's/$/\'$'\r/g'; rm -f '@TempScriptPath@' "

This feeds the script into tr which removes the carriage returns, pipes through /bin/sh to execute, and the output is filtered through sed so that carriage returns are added into the output so that it is easy to work with in Windows world. Finally it removes the temporary script after execution. If you choose to Wait For Process, the command output is available in the "%executeresult%" variable.

 

I have attached a small script I pulled out and trimmed down to demonstrate this. This script is designed to run on OSX and prevent the machine from going idle. That was a big problem I have had with OSX, at night in low power mode it will wake every few minutes, check into LabTech and retrieve a command and then go back to sleep. It might be 5-15 minutes later before it returns the result of the command which makes scripts take forever, if they can manage to complete at all. I just run this code to block idle/sleep for a specified number of minutes at the beginning of my maintenance window and then the agent stays online and pays attention to the other script steps.

 

Darren

OSX Prevent Idle Sleep.zip

Share this post


Link to post
Share on other sites

That's pretty slick. Another tip: can't do file download on Mac (at least reliably). So we use curl to directly download from our LT transfer folder.

Share this post


Link to post
Share on other sites

@kevinjackson Sorry for never responding. I didn't get a notification email and just logged back in today.

The URL for your transfer folder is:  https://<your_cwa_fqdn>/labtech/transfer/xxxxxxxxxxxxxxxxxxx

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...