This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Variables in Scripts

Not sure if I'm missing something, but wondering if it's possible to use Alert type variables within scripts. I have quite a few F5 devices that I want to script UCS backups on, but need each filename to be unique in order to do this in a single job. If there was a way to port in something like ${NodeName} within the script, I could create a generic script and run against many like devices.I have a working static filename script working on a single device but hoping to prevent the need to create 20 almost identical jobs to accomplish this. Anyone figure this out yet?

  • I think a Config Change Template would do what you need to do.

    Take a look at A Few Tips and Tricks When Creating NCM Config Change Templates and More Automation in NCM: Usage of Variables and Custom Properties in Command Scripts and Config Change Templates

    You should be able to insert the @ ContextNode variable as the filename in the script and run the template against all of your F5 devices. If you need to add additional variables, the section below has an example (from the first link above).

    How to Add Variables to CLI Statements

    You may want to include certain variables, that you normally use e.g. in device templates, in your CCT. This approach helps you keep your template as device-independent as possible. Additionally, you can include e.g. IP address (of your TFTP server, for example) in a clean way which will not make you modify the CCT source code when this IP address changes. The trick is basically identical to the previous case. The following fragment can be used e.g. when handling firmware.

    script BaseChangeTemplate(NCM.Nodes @ContextNode)

      string @myTFTPImage='${StorageAddress}' + '/image.bin'    ${StorageAddress} is the IP address of TFTP server that comes with NCM. It is used e.g. in device templates for config downloads.

      CLI

      {

        copy tftp://@myTFTPImage flash                          You do not have to hard-code the IP address in the command.

        ...

      }

    }

    Resulting script:

    copy tftp://${StorageAddress}/image.bin flash

  • Thats perfect! I was able to create a change template using the @ContextNode.SysName variable and get the filename correct. I'm now having an issue where it's changing the file path from save /var/tmp/@FileName to /var mp/@FileName. I have a ticket open, but at least this is a great start.

    {

    string @FileName= @ContextNode.SysName + '.ucs'

    string @SCPPath='scpuser@xxx.xxx.xxx.xxx:/Config-Backups/F5/' + @FileName

         CLI

         {

    tmsh

    save /sys ucs /var/tmp/@FileName

    y

    quit

    scp /var/tmp/@FileName @SCPPath

    scppassword

        }

  • Hi Andy,

    This is a specific problem when the path includes /t which gets expanded as whitespace. Please change it so it doesn't include this sequence.

    See Escape characters for string variables.

    Regards,

    Jiri

  • There is a way around the /t issue by using an NCM macro.

    I don't have a UCS to test but sending the commands to a switch gives me the following output (I excluded the 'quit' command):

    tmsh

    save /sys ucs /var/tmp/mydevicesysname.ucs

    y

    scp /var/tmp/mydevicesysname.ucs scpuser@xxx.xxx.xxx.xxx:/Config-Backups/F5/mydevicesysname.ucs

    scppassword

    Try the following:

    In NCM Settings - Manage Macros, create a new Macro called UCSPath with a value of /var/tmp/

    pastedImage_1.png

    pastedImage_2.png

    Then edit your script to reference the macro.

    script runUCSScript(

                        NCM.Nodes @ContextNode

        )

    {

      string @FileName=@ContextNode.SysName+'.ucs'

      string @UCSFileName='${UCSPath}'+@FileName

      string @SCPPath='scpuser@xxx.xxx.xxx.xxx:/Config-Backups/F5/' + @FileName

      CLI

      {

        tmsh

        save /sys ucs @UCSFileName

        y

        quit

        scp @UCSFileName @SCPPath

        scppassword

      }

    }