Hi All,
I have a WS-8-250-AC test unit on my bench, and it upgraded to the latest firmware without issues. So far, so good!
I am happy enough navigating my way through the CLI but I'd like a little guidance on running CLI commands in a script from the shell.
So my basic question is how do I run CLI commands from the underlying Linux shell in a way that I end up back at the shell.
My driver is that I would like to be able to run scripts either from cron or at boot, which use CLI commands to check for link states, and run other CLI commands based on the results. Running a single CLI command from the shell is the first step towards this.
Thanks for any insights you may be able to give me.
Scripting CLI commands on WS-8-250-AC
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
-
Eric Stern - Employee
- Posts: 532
- Joined: Wed Apr 09, 2014 9:41 pm
- Location: Toronto, Ontario
- Has thanked: 0 time
- Been thanked: 130 times
Re: Scripting CLI commands on WS-8-250-AC
Use the "cmdline" CLI command to drop to the linux shell.
Run your commands.
Use the "exit" command to return to the CLI.
Run your commands.
Use the "exit" command to return to the CLI.
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
Re: Scripting CLI commands on WS-8-250-AC
Thanks for the reply, but I want to do this the other way round.
Start from the linux shell, run a CLI command and end up back at the linux shell.
Start from the linux shell, run a CLI command and end up back at the linux shell.
-
sirhc - Employee
- Posts: 7490
- Joined: Tue Apr 08, 2014 3:48 pm
- Location: Lancaster, PA
- Has thanked: 1643 times
- Been thanked: 1336 times
Re: Scripting CLI commands on WS-8-250-AC
When you SSH into the device you land in the CLI, there is no way to initially land in the Linux Shell (that I know of)
You would need your script to issue the CMD command in the CLI to drop to the Linux shell do what ever you want to do then issue the EXIT command
You would need your script to issue the CMD command in the CLI to drop to the Linux shell do what ever you want to do then issue the EXIT command
Support is handled on the Forums not in Emails and PMs.
Before you ask a question use the Search function to see it has been answered before.
To do an Advanced Search click the magnifying glass in the Search Box.
To upload pictures click the Upload attachment link below the BLUE SUBMIT BUTTON.
Before you ask a question use the Search function to see it has been answered before.
To do an Advanced Search click the magnifying glass in the Search Box.
To upload pictures click the Upload attachment link below the BLUE SUBMIT BUTTON.
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
Re: Scripting CLI commands on WS-8-250-AC
But what if I want to run a script on the device? So if I wanted to place a script in some directory on the switch and call it from the switch's cron? Then it would run from the Linux (ash?) shell, right?
Or is there another way to achieve what I want by scheduling a CLI "script" from within CLI itself?
Essentially what I want to do is check for a link on one port, and if this link is up, disable PoE on 2 other ports, and re-enable PoE on these ports when the link on the first port shows as down.
Or is there another way to achieve what I want by scheduling a CLI "script" from within CLI itself?
Essentially what I want to do is check for a link on one port, and if this link is up, disable PoE on 2 other ports, and re-enable PoE on these ports when the link on the first port shows as down.
-
Eric Stern - Employee
- Posts: 532
- Joined: Wed Apr 09, 2014 9:41 pm
- Location: Toronto, Ontario
- Has thanked: 0 time
- Been thanked: 130 times
Re: Scripting CLI commands on WS-8-250-AC
From the script you can run "switch -s" to start the CLI. But then you would need something like "expect" to drive the CLI, but "expect" isn't available. You could probably do it with a PHP script.
Alternately you could manually change the configuration file (config.json). After changing it run "php-cli config.php --apply" from the /www directory to apply the changes.
Alternately you could manually change the configuration file (config.json). After changing it run "php-cli config.php --apply" from the /www directory to apply the changes.
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
Re: Scripting CLI commands on WS-8-250-AC
Thanks for that, that looks like it may do what I need it to, at least initially.
Especially the
allows me to check the status of an individual port.
I guess what I'll look at is having 2 versions of config.json, one for each configuration I need (in terms of PoE enabled on different ports) and switching between them depending on the output of the switch -d command.
Thanks very much for the help.
Especially the
- Code: Select all
switch -d
allows me to check the status of an individual port.
I guess what I'll look at is having 2 versions of config.json, one for each configuration I need (in terms of PoE enabled on different ports) and switching between them depending on the output of the switch -d command.
Thanks very much for the help.
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
Re: Scripting CLI commands on WS-8-250-AC
I've made good progress on this and have the system nearly configured the way I want. The one thing I'd like to check is if there is a a way to gracefully shut down the switch from the command line.
I need the switch to apply a base config with PoE disabled on all ports when it shuts down, and I have managed to add an init script which is called on a reboot as an rc script with a K prefix which does what I need it to, but the application where this switch will be used is a temporary one and I'd like to be able to shut the switch down gracefully and call the K script that way if possible at the end of the event.
Is this possible?
Thanks in advance for the help so far.
Stefan
I need the switch to apply a base config with PoE disabled on all ports when it shuts down, and I have managed to add an init script which is called on a reboot as an rc script with a K prefix which does what I need it to, but the application where this switch will be used is a temporary one and I'd like to be able to shut the switch down gracefully and call the K script that way if possible at the end of the event.
Is this possible?
Thanks in advance for the help so far.
Stefan
-
Eric Stern - Employee
- Posts: 532
- Joined: Wed Apr 09, 2014 9:41 pm
- Location: Toronto, Ontario
- Has thanked: 0 time
- Been thanked: 130 times
Re: Scripting CLI commands on WS-8-250-AC
I think you want the "reboot" command.
-
spynappels - Member
- Posts: 15
- Joined: Wed Oct 14, 2015 5:37 am
- Location: United Kingdom
- Has thanked: 3 times
- Been thanked: 0 time
Re: Scripting CLI commands on WS-8-250-AC
I got that. Doesn't work from CLI though.
I'm assuming that there is also no shutdown equivalent, given that it is not normal practice to shut them down. I reckon I've got a workaround in any case. Thanks for the response though.
Just a follow on question:
If the firmware is upgraded, is the /etc/init.d directory cleared? I ask because I have added a line to the netonix init script and I'd like to verify whether it is persistent across upgrades. I suspect not, but it would be nice to have that confirmed. The same goes for the /usr/bin/ directory, where I have added a script.
Who is online
Users browsing this forum: Google [Bot] and 18 guests