Bash Shell

Version

This feature requires version 1.8.0 or later

The Cisco Nexus 3550-F Fusion (formerly ExaLINK Fusion) command line interface provides access to a bash shell, which supports many standard UNIX commands and the ability to run scripts.

Accessing the Bash shell

To access the bash shell from the CLI, use the bash command:

admin@N3550-F> bash

ExaLINK Fusion shell

admin@N3550-F:~$

The bash command is only available to users with the admin role.

Directories

  • /media/userfs contains the startup configuration and other files which need to persist across updates. This is the only part of the filesystem that is preserved on a firmware update.
  • /media/userfs/debug is a temporary directory for debug dumps. Its contents does not persist across reboots.
  • /media/userfs/update is a temporary directory for firmware updates. This also does not persist across reboots.

Note that home directories are also temporary and no user files may be placed in them. Files which need to persist should be placed in /media/userfs.

Shell scripting

Shell scripts should be placed in /media/userfs or in a subdirectory and must have #!/bin/bash or #!/bin/sh as the first line. The executable bit will automatically be set for these files.

Using Cisco Nexus 3550-F Fusion commands from the shell

The Nexus 3550-F command interpreter can be accessed from the Bash shell using the cli command. Commands can be provided to the command interpreter using the -c argument, for example:

admin@N3550-F:~$ cli -c 'show port'
Port Status Description
---- ------ -----------
...

This is useful if you want to use unix shell commands such as grep together with Nexus 3550-F commands, for example:

admin@N3550-F:~$ cli -c 'show port' | grep 'down'

It can also be used to run commands from shell scripts.

Python scripting

The Nexus 3550-F has a Python interpreter installed.

admin@N3550-F:~$ python
Python 2.7.3 (default, Jun  5 2017, 12:52:39)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Bindings are provided for access to the JSON-RPC API. This can be accessed by importing the module exalink.

>>> import exalink

This creates an exalink object in the current namespace. Fusion JSON-RPC API calls can be accessed as methods of this object, for example:

>>> print exalink.get_ports()

Python scripts should be placed in /media/userfs or in a subdirectory and must have #!/usr/bin/python as the first line. The executable bit will automatically be set for these files.

Cron jobs

The Nexus 3550-F supports cron for running user-defined tasks at scheduled times.

The Cron configuration file is called crontab. This file can be edited by running the command crontab -e in the bash shell:

admin@N3550-F:~$ crontab -e

Note that the crontab utility on the Nexus 3550-F is specially modified to always edit the admin user's crontab. This means any users with access to the bash shell can edit the same crontab, and that all cron jobs will run as the user admin.

Here is an example crontab for running a script every 5 minutes:

*/5 * * * * /media/userfs/hello.py

Each line consists of 5 fields followed by a command. The 5 fields specify the time and day the command is to be run. In order, they are:

  • Minute (0 to 59)
  • Hour (0 to 23)
  • Day of month (1 to 31)
  • Month (1 to 12)
  • Day of week (0 to 6)

Each field can be a number, a comma-separated list (eg. 5,10,15), or *. The / syntax is also supported, so for example */5 in the first field means every 5 minutes.

Use the crontab -l command to list the current cron configuration:

admin@N3550-F:/media/userfs$ crontab -l
*/5 * * * * /media/userfs/hello.py

This page was last updated on Feb-19-2021.