take SN from civ and run terminal command

ImAMacGuy
Valued Contributor II

I want to take an exported list of SNs from jamf and run a command in terminal against it, what's the easiest way to do that?  

9 REPLIES 9

Tribruin
Valued Contributor II

Can you be more specific about what you are trying to accomplish. Your ask is very vague. 

 

Are you trying to run commands on each computer in the list or run a command on your computer that does something to all the computers in list

ImAMacGuy
Valued Contributor II

Sorry, yes, I have a list of machines that haven't checked in for XX days, and I want to export the SN from those and then run a command in terminal 

jbsh SERIALNUMBER

against each SN from the list.  I'm doing it manually currently but there's hundreds of them.

 

jcarr
Release Candidate Programs Tester

So, you just want to run a loop against a list of serials?  If it were me, I'd set up a script using one of the linked examples, and input the list from a .csv text file.  If you do it often enough, take it a step further and set up a folder action that runs when you export the list from Jamf into a particular folder.

ImAMacGuy
Valued Contributor II

thanks @jcarr doesn't seem that I can call the command under sudo (it's part of .zshrc located in the user's folder, just returns command not found.  

 

Is there a way I can run a terminal command similar to this? 

jbsh $serial from ~/Downloads/sn.csv

 

 

I've tried looking at the examples and googling, but I'm not sure of the correct verbiage, so none of the results have been helpful.

 

jcarr
Release Candidate Programs Tester

As @Tribruin points out, this question is still a little vague.  If you are looking to run a script on one device, and take action on a number of devices (e.g. via API calls), you could do something like this:

 

#!/bin/sh

while read serial
do
	#	Some action here.
	echo "Serial:			${serial}"
done < serials.csv

exit 0

 

Where the script and the file 'serials.csv' (a simple text file with serial numbers separated by carriage returns) are in the same folder.

 

Running a policy on devices where they set values based on their serial number and a corresponding value in a .csv is a different story however.

ImAMacGuy
Valued Contributor II

I have a bunch of machines that aren't reporting in, I was going through and using Jamf Self Heal to setup the ~/.zshrc setup outlined in the link to make it easier to fix the binary/restore MDM.  

To run it manually, I just type in terminal (no sudo) `jbsh SERIALNUMBER`. that seems to work, but it's a manual- one at a time- process and I've got nearly 200 to do.  

I want to see if I can export the list of SNs from jamf that aren't checking in, and find a way to automate running jbsh against the serial numbers exported from jamf.  I believe the .zshrc commands are tied to using my regular user account, so I'm looking for a way to do a manual one-liner from terminal to run the command w/o sudo.

 

 

Tribruin
Valued Contributor II

As @jcarr mentioned above, you would need to write a script that loops through each serial number read from a CSV and then issues the jbsh command to that serial number. jbsh is not write to receive SNs in mass. 

 

jcarr
Release Candidate Programs Tester

Ah, ok.  I haven't run the Self Heal util, but if it's just a command run from your computer locally, you should be able to call it in the "# Some Action Here" line.

 

If the self heal util requires admin rights, there isn't any way to get around using sudo, but if it's just reaching out to remote computers, using an account that has admin rights on the remote device, then you should be able to run it on your device without sudo (since you aren't making any changes to your device).

ImAMacGuy
Valued Contributor II

I think the problem is that when I run the shortcut command `jbsh SN` it runs under my user account, pulling the shortcut from the ~/.zshrc file.  

When I try to run the jbsh command through a script to pull against the CSV, it runs under sudo (sudo ./script) and can't find the jbsh shortcut command.