0

Q. How to automate Network Link Conditioner to toggle ON/OFF for a set time period

I am on the latest Mac OS software (at the time of writing this) - Ventura 13.4

In basic terms, I am looking to repeatedly activate and deactivate Network Link Conditioner for any given amount of time.

However, when running the .sh file in a terminal window with the code above, I get several syntax errors.

I am very new to all things scripting etc. Any help would be appreciated.

This is the code I have been working on:

#!/bin/bash

set variable "nlc"="network-link-conditioner";

async function example(){
nlc.setDelay(1);

const profiles=await nlc.getProfileNames();
await nlc.setProfile(profiles[1]);
await nlc.setProfile("100% Loss");

await nlc.on();
await nlc.off();
}
example();
  • copy/paste your code into https://shellcheck.net and fix the flagged errors. (Hints, bash sets variable values with the `var="value"` syntax, function declarations don't carry a return type at the front, use `myFn(){ do fn stuff}`. There is a utility/mini-lang called `expect` that may be o help to you. It is well documented and if you search or `[expect]` you'll likely find a lot of good examples. Good luck. – shellter Jun 10 '23 at 23:03
  • Thanks for your help. I've managed to fix the first error. The function error is still occurring however. What do you mean by _don't carry a return type at the front_? I'm a real novice when it comes to scripting etc. Could you paste the code without the errors? Thanks again. – user893468 Jun 11 '23 at 10:36
  • Your code doesn't look like any `bash` code I'm familiar with. Items like `nlc.setDelay(1)` look like a class method. In the languages I'm familiar with, `async function example()`. the `async` is a programmer specified type of what sort of object (or data type) is to be returned by the function. A compiler uses that to ensure all usage of the function complies with that specification. ...... SO, **I need the command(s) that can be executed on the command line that does the simplest version of** ***activate ... Network Link Conditioner***. .... – shellter Jun 11 '23 at 15:53
  • With my limited knowledge of networking, NLC sounds like software that runs on network hardware (switch/router/firewall). Do you know for certain that your Mac has NLC software built in? – shellter Jun 11 '23 at 15:58
  • When I search here on StackOverflow for `Network link conditioner* I see almost 300 Q/As. Have you looked at any of them? – shellter Jun 11 '23 at 16:11
  • After reading what NLC was, I realized your headline question should be "how to script NLC". See here https://stackoverflow.com/a/56224458/620097 for one answer. This is all the time I have for your issue. I recommend you delete here and post to a more Mac specific area ([apple.se]) . Sorry to be abrupt, but thanks very much for making me aware of NLC, that's a interesting tool. Good luck – shellter Jun 11 '23 at 16:25

0 Answers0