Scripting CLI commands on WS-8-250-AC

DOWNLOAD THE LATEST FIRMWARE HERE
User avatar
spynappels
Member
 
Posts: 15
Joined: Wed Oct 14, 2015 5:37 am
Location: United Kingdom
Has thanked: 3 times
Been thanked: 0 time

Scripting CLI commands on WS-8-250-AC

Thu Dec 03, 2015 10:32 am

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.

User avatar
Eric Stern
Employee
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

Thu Dec 03, 2015 11:22 am

Use the "cmdline" CLI command to drop to the linux shell.
Run your commands.
Use the "exit" command to return to the CLI.

User avatar
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

Thu Dec 03, 2015 11:24 am

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.

User avatar
sirhc
Employee
Employee
 
Posts: 7415
Joined: Tue Apr 08, 2014 3:48 pm
Location: Lancaster, PA
Has thanked: 1608 times
Been thanked: 1325 times

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

Thu Dec 03, 2015 11:30 am

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
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.

User avatar
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

Thu Dec 03, 2015 11:34 am

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.

User avatar
Eric Stern
Employee
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

Tue Dec 08, 2015 3:35 pm

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.

User avatar
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

Wed Dec 09, 2015 3:44 am

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.

User avatar
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

Tue Dec 22, 2015 6:57 am

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

User avatar
Eric Stern
Employee
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

Tue Dec 22, 2015 11:37 am

I think you want the "reboot" command.

User avatar
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

Tue Dec 22, 2015 11:51 am

: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.

Next
Return to Hardware and software issues

Who is online

Users browsing this forum: No registered users and 33 guests