scripting an FTP file upload using a file with an unknown name ending in .txt

I have the following commands configured in a script:

/system gps
monitor file=[/system identity get name]

The output of the above command creates a file with the GPS location using the syntax “hostname.txt”. It forces the .txt extension on this file even if I don’t specify it.

I then issue a command to upload the newly created file to an FTP location. The problem is that the filename will vary from system to system as it’s based on the hostname. Is there anyway to specify a variable in the “/tool fetch upload” command?

This does work, but I have to specify the exact filename:
/tool fetch upload=yes mode=ftp address=x.x.x.x src-path=“SourceFile.txt” dst-path=“SourceFile.txt”

I would like to work out the proper syntanx that would allow the file name to be based on the identity and add “.txt” to end of that variable:

So, for example something similar to this is what I need, but this syntax does NOT work with the “.txt” added on to the variable section [/system identity get name].

/tool fetch upload=yes mode=ftp address=x.x.x.x src-path=[/system identity get name].txt dst-path=[/system identity get name].txt

You were close:

:local myname [/system identity get name]
/tool fetch upload=yes mode=ftp address=x.x.x.x src-path="$myname.txt" dst-path="$myname.txt"

Awesome. Thank you, I think that will work for us!

Note that in order for this to work, we had to use the word global instead of local:

:global myname [/system identity get name]

You could have used concatenate operation also:
/tool fetch upload=yes mode=ftp address=x.x.x.x src-path=([/system identity get name].“.txt”) dst-path=([/system identity get name].“.txt”)

No you do not need to use :global instead of :local, only if run from the console, since each statement is then treated as independent scope, unless it is part of a common block (i.e. in {})

{
:local myname [/system identity get name]
/tool fetch upload=yes mode=ftp address=x.x.x.x src-path="$myname.txt" dst-path="$myname.txt"
}

but you don’t need a variable at all

/tool fetch upload=yes mode=ftp address=x.x.x.x src-path=([/system identity get name] .".txt") dst-path=([/system identity get name] .".txt")

I suggested the variable because it makes the resulting code easier to read.

In fact, you could use ; on the command line and local should work that way also.

I just did this on my command line:

[admin@zerobyte.org] > :local foo ROFL ; :put $foo
ROFL
[admin@zerobyte.org] >

I’m all for teaching good practice, the reason I commented in the first place. Putting multiple statement in on line separated with semikolon would sure work, but personally I am not a fan of multi statement lines, they are no easy read. All down to taste of course.