Script for If enivorment = then do

Hi Am try to figure out how to make a script that runs download file based on that status of environment value

here is the current code am try to get work

:global configserver “http://192.168.1.187//$macaddress/temp.rsc
:global “provisioned-status” “no”
:if (($provisioned-status=“no”)) do={/tool fetch url= $configserver output=file}
:if (($provisioned-status=“no”)) do={:log info “download provision”}
:if (($provisioned-status=“yes”)) do={:log info “already provision”}


/tool fetch url= $configserver works fine to grab the config file maybe am missing some bracket or something any suggestions?

Yeah, you have a blank after “url=” → remove the blank.
And In the url you have double slashes after the IP → should be just one slash.

Hi ya the double slash was cause i edit the URL forgot to remove it had a folder name

I assume this what you meant for edit

:global “provisioned-status” “no”
:if (($provisioned-status=“no”)) do={/tool fetch url=$configserver output=file}
:if (($provisioned-status=“no”)) do={:log info “download provision”}
:if (($provisioned-status=“yes”)) do={:log info “already provision”}

still nothing the script run no error nothing logged in the systems logs

Have you tried removing the quotation around the name of the global variable ??

:global “provisioned-status” “no” into :global provisioned-status “no”

Variable name contains arithmetic character. I would suggest to avoid creating such variable names, but if you still do then remember that such names must be always in double quotes, like in this example:

:global "not-good-var-name" "x"
:put $"not-good-var-name"

Thanks you both the name is was issues in bracket i change it to this now download it only issues is if i used yes it does not accept it as viable and change it it true? if low case but if caps it accepts it?? any suggestions on how do with only one like say no?

:global configserver “http://192.168.1.187/~andyasselin/$macaddress/temp.rsc

:global “provisionedstatus” “no”
:if (($provisionedstatus=“no”)) do={/tool fetch url= $configserver output=file}
:if (($provisionedstatus=“no”)) do={:log info “download provision”}
:if (($provisionedstatus=“yes”)) do={:log info “already provision”}

{
:global provisionedstatus false
:if $provisionedstatus do={} else={/tool fetch url= $configserver output=file; :log info "download provision"}
:if $provisionedstatus do={:log info "already provision"}
}

Hi It works just curios why this won’t work inside system scripts work at the console if run as script use /import says invalid URL not sure how to debug that i assume it same URL it pull for from $configserver not sure why won’t run as a script any suggestions?

I already told you the reason in posting #2: you have some excess blanks (space char)…

Not ok:

:if $provisionedstatus do={} else={/tool fetch url=> > $configserver output=file; :log info “download provision”}

OK:

:if $provisionedstatus do={} else={/tool fetch url=$configserver output=file; :log info “download provision”}

I should have said i did remove the space it still wont run as script under

I think its the else that makes problem.
Can not see in your script that you have set the macaddress. All variables needs to be set or declared.
Do not use global variable if you do not need it. Only when passing data from one script to another or store the variable for later use.
Even then you need to declare the global variable before use.

{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if $provisionedstatus do={/tool fetch url=$configserver output=file; :log info "download provision"}
}

Or

{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=true) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}

Or

{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=false) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}

Thanks will give them try tomorrow to let you know I feel like with this code am get closed to what i want to do
maybe I should probably try the script use the sn vs mac address just to test that I was testing on a virtual machine so it did not have sn to use
now test on hap ac as said the script fun fine pasted into the cli terminal window but it doesn’t run as import script or system script I am going try it maybe I cant use fetch in system script seem odd would have figured that script should have work in both system script and cli if was go to work



sorry i am set the mac via script

#/interface ethernet get ether1 mac-address
:log info “ethernet-mac-to-viable”
:global macaddress [/interface ethernet get ether1 mac-address]



and this does work at cli to fetch the file

any idea why they would not work as system scripts?

your sample with log on one and download does work I used your mac address field viable

Hi Any idea why won’t run a system script?