reading variables from text file in MaxL - essbase

SET USER=3092870062612032450309212768828033911960
SET PW= 11924680696448007706606097772500386367703037421296151222544191726011595198996750
FOR /f "eol=; tokens=1,2 delims=, " %%i in D:\Hyperion\Automation\MaxL\subvar.var do echo
alter database %%j.%%k set variable %%i %%l; | essmsh -s Localhost -l
3092870062612032450309212768828033911960 11924680696448007706606097772500386367703037421296151222544191726011595198996750 -i
I am in the process of automating substitution variables in our ASO cube. I have prepared subvar.var file which contains the variables. Is there a way to read them through MaxL and update the cube dynamically?
I tried using the above code and it is returning error.
Subvar.var file: OPS OPS lastmth Jun 2015 OPS OPS currmth Jul
2015

Related

Retry a sql query in case of failure in batch

This script processes all the sql files in a given folder and outputs the result to a csv. Do you have any ideas how could I adapt it to retry the sql file in case of error or failure?
#ECHO OFF
SET SQLCMD="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"
SET PATH="C:\Users\username\Desktop\Scripts\Reports\sql"
SET SERVER="localhost"
SET DB="database"
SET LOGIN="username"
SET PASSWORD="password"
SET OUTPUT="C:\Users\username\Desktop\Scripts\Reports\output_%date%-%time:~0,2%-%time:~3,2%-%time:~6,2%.csv"
CD %PATH%
ECHO %date% %time% > %OUTPUT%
for %%f in (*.sql) do (
%SQLCMD% -S %SERVER% -d %DB% -E -i %%~f >> %OUTPUT% -W -w 1024 -s";")
Thank you!
You cant test the ERRORLEVEL environment variable. typically a zero ERRORLEVEL value means success. also you need to enable delayed expansion to check it inside a block.
something like this may help,
SetLocal EnableDelayedExpansion
for %%f in (*.sql) do (
Set /a success=1
for /L %%w in (1,1,5) do ( rem retry five times
if !success! NEQ 0 (
%SQLCMD% -S %SERVER% -d %DB% -E -i %%~f >> %OUTPUT% -W -w 1024 -s";"
if !ERRORLEVEL! EQU 0 set /a success=0
)
)
if !success! NEQ 0 (
rem sql failed, log or advise
)
)
EndLocal
another important point, be careful with the PATH environment variable. you should better use another name as SQL_PATH or MY_PATH.
or you can use PUSHD & POPD to change your working dir
#echo off
SET ...
rem save current dir and jump to...
pushd "C:\Users\username\Desktop\Scripts\Reports\sql"
for %%f in (*.sql) do (
...
...
)
rem restore dir saved by pushd
popd

how export a table of database postgres to a csv with qt?

Already has the connection succesful.
With qtsqlquery. Seem imposible execute the copy sentence of the postgresql.
For example:
execute this query on qt:
COPY table TO 'D:/table.csv' DELIMITER ',' CSV HEADER;
After study a little bit, found a script on the folder of installation of PostgreSQL (.../scripts), then modified the script to executed the command COPY TO. Because the QSQLQUERY Definitely don't executed the command COPY. Here are the Script on win7.
for /f "delims=" %%a in ('chcp ^|find /c "932"') do # SET CLIENTENCODING_JP=%%a
if "%CLIENTENCODING_JP%"=="1" SET PGCLIENTENCODING=SJIS
if "%CLIENTENCODING_JP%"=="1" SET /P PGCLIENTENCODING="Client Encoding [%PGCLIENTENCODING%]: "
REM Run psql
"D:/PostgreSQL\bin\psql.exe" -h localhost -U USER -d DATABASE -p 5432 --no-password --command="\copy (select * from TABLE) TO './EXPORT_TABLE.csv' CSV HEADER"

New folder for every backup CMD

I am trying to get a batch going to backup a folder on a work server. (Please see attached link)
Bat Error "invalid number of parameters"
Long story short - I need the script to name a new folder for each backup, which "md new_folder" was suggested, but I cannot seem to get the context or how to place it into the code.
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
#echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKINGUP SOME DATA########
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
Any help would be greatly appreciated!
----------EDIT:
I tried a line of code that slowly got me closer:----------
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
#echo off
:: variables
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~5,2%-%date:~8,2%-%date:~0,4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y
echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy %SRCFOLDER% "%DESTFOLDER%\%folder%" %backupcmd%
echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
BUT - I am getting the following output:
This will now create a new backup of S:\Internal Auditor\9 - September 14
Access is denied.
Error occurred while processing: S:\Internal.
A subdirectory or file Auditor\2014\9 already exists.
Error occurred while processing: Auditor\2014\9.
A subdirectory or file - already exists.
Error occurred while processing: -.
A subdirectory or file Sept already exists.
Error occurred while processing: Sept.
A subdirectory or file Backup\9/-9/-Tue already exists.
Error occurred while processing: Backup\9/-9/-Tue .
######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
Invalid number of parameters
!!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
Press any key to continue . . .
----------EDIT 2: I tried a line of code that slowly got me closer:----------
I have followed the suggestions and some things I found online, and now I am to the point where I am getting a few errors:
md "S:\Internal Auditor\~\09/12/2014"
A subdirectory or file S:\Internal Auditor\~\09/12/2014 already exists.
And:
xcopy "S:\Internal Auditor\9 - September 14 S:\Internal Auditor\2014\9 - Sept Backup\09/12/2014
/W /E /H /V /C /Z /I /F /J /R /Y /D
File not found - 09/12/2014 /W /E /H /V /C /Z /I /F /J /R /Y /D
This is my code:
#echo This will now create a new backup of S:\Internal Auditor\9 - September 14
Rem Backup 9 - September 14
#echo
:: variables
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"
set folder=%date:~4%
md "%DESTFOLDER%\%folder%"
set backupcmd=/W /E /H /V /C /Z /I /F /J /R /Y /D
#echo ######## PLEASE WAIT SYSTEM BACKING UP SOME DATA########
xcopy "%SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%"
#echo !!!!!!!!BACKUP COMPLETED THANKS!!!!!!!!!!!!!!
#pause
Also, when I run the code, it makes a new directory ~\09\12\2014 instead of the desired ~\09/12/2014.
Clarification:
It makes 3 new subdirectories instead of one new subdirectory.
Okay let's see what you're doing. Your variable folder is being set based on your local settings for a short date, which for me shows e.g. Tue 09/09/2014 so your %date:~0,4% would be Tue. Use the echo command to be sure you're getting what you want:
echo %date:~5,2%-%date:~8,2%-%date:~0,4%
But let's assume for now you already figured that out and %folder% contains what you want it to. This is two commands on a line, which won't work at best at at worst is going to create a bunch of folders you didn't expect:
"md new_folder" xcopy %SRCFOLDER% %DESTFOLDER% %backupcmd%
You want to split that into 2 lines, and you want to use your new date-based folder name as part of the destination, I'm sure. So this will do that:
md "%DESTFOLDER%\%folder%"
and then to copy you'd need to include \%folder% in your destination:
xcopy %SRCFOLDER% %DESTFOLDER%\%folder% %backupcmd%
But I think, and I know I shouldn't ask for clarification but perhaps if I'm wrong you should clarify what you need a bit more in your question, you really want that S:\Internal Auditor\2014\9 - Sept Backup to be S:\Internal Auditor\ plus the value in %folder% and not having the date the way it is in that path.
Suggestion: Make the %folder% variable to be yyyy-mm-dd format such as 2014-09-09 so it's sortable, and use that in your destination.
Ok. There are some errors:
set SRCFOLDER="S:\Internal Auditor\9 - September 14"
set DESTFOLDER="S:\Internal Auditor\2014\9 - Sept Backup"
Must be (safe method, adding first quote at start of SRCFOLDER and DESTFOLDER):
set "SRCFOLDER=S:\Internal Auditor\9 - September 14"
set "DESTFOLDER=S:\Internal Auditor\2014\9 - Sept Backup"

how to save a tree as the active username using a pipe

I am currently trying to make a file that will run a tree command that saves the file as the name of the active user. %userprofile% has C:\ in it and wont work. how do i set %user% to be the name of the user? if this is impossible, then is there a way i can save it as the output of a hostname command?
#echo off
cd %userprofile%
tree /a /f > "J:\folder1\%user%"
Attrib +H +S "J:\folder1\%user%"
Replace %user with %USERNAME%:
#echo off
cd %userprofile%
tree /a /f > "J:\folder1\%USERNAME%"
Attrib +H +S "J:\folder1\%USERNAME%"
Also, I suggest you look into the set command. If you run it without any parameters it will show you all the available environment variables.

Batch file that returns folder size

I'm having space issues on my Vista machine and need to figure out what's taking up so much space.
I would like to write a simple batch file that returns all folders under C: and the size of each folder.
The dir command doesn't appear to return folder size.
Unfortunately we don't have admin rights and can't install a third party application and we have other users in our group that also need this information.
I'd have a look at this thread for some clues as to how to achieve the directory size:
Batch File To Display Directory Size
Otherwise:
dirsize:
#echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/1024
set /a sum=!sum!+!value!
)
#echo %CD%:!sum! k
AllDirSize:
echo off
set WORKING_DIRECTORY=%cd%
for /f "delims=" %%a in ('dir /a:D /D /B /S') do (
echo off
cd %%a
"%WORKING_DIRECTORY%"\dirsize "%%a"
cd %WORKING_DIRECTORY%
)
Use it: ALLDIRSIZE > C:\temp\FileContainingFolderSizes.txt
Which is taken from the excellent Richard Bishop testing forums: http://www.bish.co.uk/forum/index.php?topic=58.0
Not exactly answering your question, but if you have GUI access I'd suggest using TreeSize:
http://www.jam-software.com/freeware/index.shtml
If you prefer command line use du command from Unix utils:
http://unxutils.sourceforge.net/