Topic "Use of Environment Variables in Scripting"

Author Message
katmanrocks

Guest


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%.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Are you sure the ENV variable is set in the MSQL environment? Have you read this FAQ?
_________________
Martin Prikryl
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.
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License