Page 1 of 2

Scripting CLI commands on WS-8-250-AC

Posted: Thu Dec 03, 2015 10:32 am
by spynappels
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.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Thu Dec 03, 2015 11:22 am
by Eric Stern
Use the "cmdline" CLI command to drop to the linux shell.
Run your commands.
Use the "exit" command to return to the CLI.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Thu Dec 03, 2015 11:24 am
by spynappels
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.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Thu Dec 03, 2015 11:30 am
by sirhc
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

Re: Scripting CLI commands on WS-8-250-AC

Posted: Thu Dec 03, 2015 11:34 am
by spynappels
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.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Tue Dec 08, 2015 3:35 pm
by Eric Stern
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.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Wed Dec 09, 2015 3:44 am
by spynappels
Thanks for that, that looks like it may do what I need it to, at least initially.

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.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Tue Dec 22, 2015 6:57 am
by spynappels
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

Re: Scripting CLI commands on WS-8-250-AC

Posted: Tue Dec 22, 2015 11:37 am
by Eric Stern
I think you want the "reboot" command.

Re: Scripting CLI commands on WS-8-250-AC

Posted: Tue Dec 22, 2015 11:51 am
by spynappels
:rofl4:

I got that. Doesn't work from CLI though. :willy:

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.