How to use string processing with environment variable value in WinSCP command? - scripting

I want to manage (Upload\Download\Delete) a file on an FTP Server with WinSCP command line.
It says I can use environment variables! I have some text files that have the date in their name.
I just created the variable I want:
Test_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.txt
and tested it with Windows echo command. It becomes Test_20140916.txt and that is exactly what I have now.
But when I try to upload that file in WinSCP, I get this error:
winscp> put D:\FTP\Test_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.txt
File or folder 'D:\FTP\Test_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.txt' does not exist.
System Error. Code: 123.
The filename, directory name, or volume label syntax is incorrect
(A)bort, (R)etry, (S)kip, Ski(p) all:
Any idea how to resolve this issue?

WinSCP supports a timestamp formatting natively:
put D:\FTP\Test_%TIMESTAMP#yyyymmdd%
To explain why your syntax does not work: while WinSCP supports the environment variables in scripting commands, it does support only a basic syntax %NAME%, as documented:
https://winscp.net/eng/docs/scripting#syntax
To achieve, what you need, you have to resolve the value to another variable and refer to that in the WinSCP command:
set STAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
winscp.com /script=script.txt
where script.txt can use %STAMP%:
put D:\FTP\Test_%STAMP%
Also note that a value of the %DATE% is locale-specific, so make sure you test your code on the same locale on which you gonna use it. Or even better, use a locale independent wmic os get LocalDateTime:
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set LDT=%%j
set STAMP=%LDT:~0,4%%LDT:~4,2%%LDT:~6,2%

Related

Rule conflict between multiple SSH

As I try to use grunt-rsync, I come to a "code 12" error, my understanting is that I have a conflict between multiple ssh installed on my computer (Git's and cwRsync's) :
where ssh
C:\Program Files\cmder\vendor\msysgit\bin\ssh.exe
C:\Program Files\cwRsync\ssh.exe
C:\Program Files (x86)\Git\bin\ssh.exe
How can I resolve that conflict ?
Thanks a lot.
Your msysgit ssh version is taking precedence over the cwrsync one, this causes issues.
You either need to change you PATH environment variable or create a batch file to override it.
#echo off
SETLOCAL
SET CWRSYNCHOME=C:\Program Files\cwRsync
SET HOME=c:\Users\*YourUserName*\
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\bin;%PATH%
"C:\Program Files\cwRsync\bin\rsync.exe" %*
(Note: the above also sets the home directoy. You should point this to your .ssh (keys) directory)
I managed to fix this problem by simply adding a single line to my .bashrc file:
export PATH=/c/Program\ Files/cwRsync/:$PATH
This adds the cwRsync directory to the beginning of your PATH environment variable, which means that its copy of ssh moves to the top of the list when you do where ssh and consequently becomes the default.
For me, this fixed problems I was having running the grunt-rsync Grunt task from msysgit (I mention it in case anyone else is having the same problem).

WMIC command not working in .bat file

I'm new to WIMC so probably there will be simple answer to my question.
If I will open CMD and run this command:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%Windows%'" get DisplayName,Name,PathName,State,StartMode
this will generate file with all services not in windows folder.
If I will save above command in bat file and run this will generate list all services somehow ignoring WHERE statement. Running this as Administrator not changing anything.
In a batch script you have to double pump the % signs so they'll be treated as literal percent signs. Change your command to this and it'll work:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%%Windows%%'" get DisplayName,Name,PathName,State,StartMode

I am trying to open Jmeter by the batch file but it gives me a Windows error

Here is the related error its showing:
java.exe is not a recognized file as an internal or external command,
operable or external command
errorlevel=9009
i was getting the same error on WIndows 8.1(64 bit) and checked java path but it was ok
so i just run my jmeter.bat with Run as Administrator and it worked for me
Many operating systems have an environment variable such as PATH that contains a list of directories (or folders) to be searched when looking for a command to execute. Commands that can be found via the PATH are commonly called external commands. The program that reads the command line or the batch file and invoked the commands may have a number of built in commands, these are commonly called internal commands.
I suggest you examine the PATH (or equivalent) set when your java command executes from the command line and also when execution is attempted from the batch file. Compare the two and make sure the directory containing your java.exe is in the PATH.
Does not work with Java 9 beta:
Running:
C:\java -version
Gives:
java version "9-ea"
Just go into command line and run:
java -jar ApacheJMeter.jar
Set the correct Java Path (installed in your system) in Computer -> Advanced System settings -> Environment Variables -> Ok -> System Variables -> Path
I got the same issue and resolved by following the above steps.
I tried everything, this eventually worked.
Within System Variables:
PATH = "C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_101\bin"
May help someone.
This error occurs due to the path has not been set properly.
Either you can set it in environmental varialables or right click jmeter .bat file,choose edit set the path their,for reference see the jmeter.apache.org user manuals.
For me, my Java path has a space in it and jmeter said it can't find Java
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
.. I looked at the jmeter.sh script and saw it got the path from "Plugin-Ins" .. onward. I tried just commenting out the exit command after that check in the script .. and then I was able to run jmeter.
So apparently the validation logic has a bug, where the error message about can't find java is in fact not true (if Java is indeed set up correctly), so it can be ignored.
For windows 8.1 Users:
Error when trying to run jmeter.bat
Error message:
Not able to find Java executable or version. Please check your Java installation. errorlevel=2
Press any Key to continue
Resolution:
Right Click jmeter.bat and Run as Administrator.
This worked for me, hope this helps. Good luck
Set the correct JM_LAUNCH variable to java.exe
For Windows XP users set Java environment by following the steps here:
http://www.tutorialspoint.com/jmeter/jmeter_environment.htm
Note the path depends on your installed JDK.
And download the file from:
https://svn.apache.org/repos/asf/jmeter/trunk/bin/jmeter.bat
Then replace your jmeter.bat with the downloaded file.
If you have installed Java and still you get this error, please set the java_home path to below using typing below command in terminal:
export JAVA_HOME="/Library/InternetPlugIns/JavaAppletPlugin.plugin/Contents/Home"
Since I run many versions of Java.. I modified jmeter.bat.
rem JM_START - set this to "start" to launch JMeter in a separate window
rem this is used by the jmeterw.cmd script.
rem
rem =====================================================
setlocal
rem Minimal version to run JMeter
set MINIMAL_VERSION=1.8.0
set PATH=%PATH%;C:\Program Files (x86)\IBM\Java80\jre\bin <<< add This line to jmeter.bat
Copied the JAVA executable from Installed version of Java from C:\Program FilesJava\jdk1.8.0_191\bin and pasted in the folder where the jmeter bat resides and it worked for me.
Not exactly the same issue but somebody might find it helpful
Do not double click jmeter.bat but instead ApacheJMeter.jar in the same directory
For me jmeter.bat run but for a brief moment closing almost immediately and not prompting any error. Above workaround allowed me to start working
if JAVA -version shows as blank or empty in the command prompt (CMD) then you need to clear the all java paths in environment variable and again add JAVA_HOME=C:\Program Files\Java\jdk-11.0.15.1
path= C:\Program Files\Java\jdk-11.0.15.1\bin;
if you see C:\Program Files\Common Files\Oracle\Java\javapath; like this remove this
and try in new CMD prompt then Java -version will work.

sqlplus - command line select statement doesn't use login.sql settings

I have an sh script containing this:
sqlplus -S $JDBC_URL <<EOF
$1;
EOF
That works fine. However, it doesn't pick my formatting preferences from login.sql. Those settings work fine when I start SQL Plus in interactive mode.
Does anyone know how to make my script read login.sql? Is there some other file perhaps?
Depending on the version of sqlplus you are using and the operating system, you likely need to set and export the ORACLE_PATH (linux) or SQLPATH (windows) environment variable to include the directory that contains login.sql.
I just found that past version used to look in the present-working-directory but that was not happening on the linux server I was working on. Setting SQLPATH did not work either because it is used in windows; setting ORACLE_PATH did work.
Attribution for this information
You could use glogin.sql instead - see OraFAQ on SQL Plus

Multiple Job (j3)

I am trying to run a GNU make file with multiple jobs.
When I try executing ' make.exe -r -j3', the receive the following to errors:
make.exe: Do not specify -j or --jobs if sh.exe is not available.
make.exe: Resetting make for single job mode.
Do I have to add ' $(SH) -c' somewhere in the makefile? If so, where?
The error message suggests that make cannot find sh.exe. The file names indicate you are probably on CygWin. I would investigate setting the PATH to include the location of sh.exe, or defining the value of SHELL to the name (or, even, full path) of your shell.
Are you running this on Windows (more specifically, in the "windows" shell?). If you are, you might want to read this:
http://www.gnu.org/software/make/manual/make.html#Parallel
more specifically:
On MS-DOS, the ā€˜-jā€™ option has no effect, since that system doesn't support multi-processing.
Once again, assuming you're running on windows, you should get MinGW or CygWin