How do I run a script someone has posted in a comment in Git?

JAMFNoob
New Contributor III

Hey everyone - I'm very much a beginner when it comes to coding and I'm very confused as to how to utilise any that people have posted as answers to questions in Github? Most of the time someone posts a comment that has a nice script in it, but if I copy and paste that script into a notepad, save it as a .bash - do I still need to chmod it? Does doing that do something to the file itself? Previously I just pasted the code into a notepad ++, did an EOL conversion to mac and saved it but it still failed to run as a script in JAMF. Wondering if I still need to chmod the file?

1 ACCEPTED SOLUTION

Samstar777
Contributor II

Hello JAMFNoob,

Here are the steps you can follow to run those scripts locally on Mac (assuming you want to run it on Mac)

  1. it is always recommend to have a good tool, I prefer BBEdit
  2. Copy the script content from GitHub
  3. Paste it in BBEdit or TextEdit (native Mac app)
  4. save the file with extension .sh on ~/Desktop (this will save on desktop) or any other location on your Mac
  5. go to terminal
  6. run chmod +x /path/of/file (This will give executive permission to your script)
  7. run sudo sh /path/to/file (when you use sudo in terminal, make sure you have administrative account in Mac)
  8. Enter Password and see the results

Hope this will help.

 

Regards,

Sam

View solution in original post

3 REPLIES 3

Samstar777
Contributor II

Hello JAMFNoob,

Here are the steps you can follow to run those scripts locally on Mac (assuming you want to run it on Mac)

  1. it is always recommend to have a good tool, I prefer BBEdit
  2. Copy the script content from GitHub
  3. Paste it in BBEdit or TextEdit (native Mac app)
  4. save the file with extension .sh on ~/Desktop (this will save on desktop) or any other location on your Mac
  5. go to terminal
  6. run chmod +x /path/of/file (This will give executive permission to your script)
  7. run sudo sh /path/to/file (when you use sudo in terminal, make sure you have administrative account in Mac)
  8. Enter Password and see the results

Hope this will help.

 

Regards,

Sam

Hayes69
New Contributor II

@Samstar777 wrote: liteblue

Hello JAMFNoob,

Here are the steps you can follow to run those scripts locally on Mac (assuming you want to run it on Mac)

  1. it is always recommend to have a good tool, I prefer BBEdit
  2. Copy the script content from GitHub
  3. Paste it in BBEdit or TextEdit (native Mac app)
  4. save the file with extension .sh on ~/Desktop (this will save on desktop) or any other location on your Mac
  5. go to terminal
  6. run chmod +x /path/of/file (This will give executive permission to your script)
  7. run sudo sh /path/to/file (when you use sudo in terminal, make sure you have administrative account in Mac)
  8. Enter Password and see the results

Hope this will help.

 

Regards,

Sam


I appreciate the information and advice you have shared. I will try to figure it out for more.

mm2270
Legendary Contributor III

Just a few pieces of information.

First, I definitely also recommend you get yourself a decent coding/script writing application, like BBEdit or Visual Studio Code. Writing and editing scripts in TextEdit is not recommended as it often messes up the formatting and will make the script fail if that happens.

Second, when using most applications mentioned above, especially BBEdit, it's not usually necessary to do the chmod +x against the script to make it executable. The app will usually do that for you, but it's still a good thing to know how to do since there may be times you run across a script in some other way and will need to set the executable bit on it.

Lastly, if you feel confident that a script will be good as is, and don't need to test it locally first, you can always go into Jamf Pro, create a new script and copy/paste the contents directly into the window and save. Testing locally is still a good idea though, so I'm not saying you should always do this, at least not until you get good at reading scripts and understand everything that's going on in them.