Use of Environment Variables in Scripting

Advertisement

katmanrocks
Guest

Use of Environment Variables in Scripting

I am testing your use of environment variables in scripts using your BETA 4.1.4 version. When I launch the script from the inside the COMMAND.EXE window, it works fine - successfully replacing the environment variable with the actual file name stored in the system's environment. But when I launch the CMD EXEC from Microsoft SQL's job handler with the same command string, the environment variable (in the form %ENV%) does not get replaced with the stored fiel name. I have captured the logs in both occasions and that is the only difference. When I run it from SQL, it is acting like version 3 and attempts to retrieve a file named %ENV%.

Reply with quote

Advertisement

Guest

Thanks for your quick response. I checked that FAQ and the environment variable I am using is 'machine level' - not user dependent. But I did figure out what is going on. Apparently Microsoft SQL 'caches' the environment variables and values. I inserted a previously known variable %PATH% in the script and logged the results noting that the server 'path' was substituted in place of the variable. I then 'restarted' the SQL server agent - the service responsible for performing the task and it worked using my new environment variable - %FILE_TO_DOWNLOAD%'
So what I have concluded is this - environment variable usage should be noted as being potentially unreliable. It seems some server services do not refresh those values very often.
Is there any other way to pull a file where the name changes daily with the addition of the date in the format filename_yyyymmdd.zip? Can I substitute the date somehow else without rebuilding the script each day? The remote server does not remove the old copies of the file so using a wildcard would not be the best way to retrieve the file.

Reply with quote

naik.lakshman@...
Guest

Can u please tell me what is difference between system environment variable and user environment variable ?

please mail at :
naik.lakshman@gmail.com

Reply with quote

martin
Site Admin
martin avatar

naik.lakshman@gmail.com wrote:

Can u please tell me what is difference between system environment variable and user environment variable ?
System variable is shared between all users, while user variable is visible only by one user.

Reply with quote

Advertisement

You can post new topics in this forum