Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

fsantaana

Re: Script does not accept parameters from Batch launch

martin wrote:

The problem is the space after the = in this line
set scpscript= "C:\Users\username\Scripts\scp-saconvert.txt"


Thanks, This corrected the issue.

Forum can be closed.
martin

Re: Script does not accept parameters from Batch launch

The problem is the space after the = in this line
set scpscript= "C:\Users\username\Scripts\scp-saconvert.txt"
fsantaana

I posted this but was new to the forum so I kinda messed up in the username...

Any help is appreciated.
Guest

Script does not accept parameters from Batch launch

Unable to connect to host "C" when trying to launch WinSCP.com script from a batch file with variables as parameters.

If I run the command manually in the cmd window it works correctly. From the WinSCP log it appears the host name is being changed to C even though, the command output appears correct.

Scripts were sanitized to remove private info

############### Batch to launch WinSCP script ###############
@echo off
REM Set Global Variables
set scpdir= "C:\Program Files (x86)\WinSCP"
set scpexe=winscp.com
set scpscript= "C:\Users\username\Scripts\scp-saconvert.txt"
set keyfile= "C:\Users\username\Scripts\win_key.ppk"

REM Get user input for SA location and server name
set /p safolder= "Input local sa folder location:"
set /p servername="Input linux server name or IP:"
set /p userid="Input User ID:"

REM launch WinSCP script to convert Files
echo Executing WinSCP to %servername%:22 with script: %scpscript%
%scpdir%\%scpexe% /script=%scpscript% /log=c:\temp\scp_debug.log /parameter %userid%@%servername%:22 // %keyfile% // %safolder%

############### WinSCP script ###############
#Set global options
option confirm off

#Establish connection with server
open scp://%1% -privatekey=%2% -hostkey=*

#Change directory to sa locations on local and remote servers
lcd %3%
cd /home/dt

#Upload sa files to sar dir on destination
put ./sa?? sar/

#execute the saconvert script
call ./saconvert.sh

#download sar_all file
get sar/sar_all

exit

############### WinSCP log output ###############
. 2017-01-06 10:56:03.060 --------------------------------------------------------------------------
. 2017-01-06 10:56:03.060 WinSCP Version 5.9.2 (Build 6958) (OS 6.3.9600 - Windows 8.1 Enterprise)
. 2017-01-06 10:56:03.060 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2017-01-06 10:56:03.060 Log level: Normal
. 2017-01-06 10:56:03.060 Local account: DOMAIN\username
. 2017-01-06 10:56:03.060 Working directory: c:\Program Files (x86)\WinSCP
. 2017-01-06 10:56:03.060 Process ID: 16488
. 2017-01-06 10:56:03.060 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console=592 /consoleinstance=_9220_403 "/script=" "C:\Users\username\Scripts\scp-saconvert.txt" "/log=c:\temp\scp_debug.log" "/parameter" "user@172.27.9.10:22" "//" "C:\Users\username\Scripts\win_key.ppk" "//" "C:\Users\username\Desktop\DTInfo-scldf-server1-2017.01.04-15.44.11\var\log\sa"
. 2017-01-06 10:56:03.060 Time zone: Current: GMT-5, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/12/2017, DST End: 11/5/2017
. 2017-01-06 10:56:03.060 Login time: Friday, January 6, 2017 10:56:03 AM
. 2017-01-06 10:56:03.060 --------------------------------------------------------------------------
. 2017-01-06 10:56:03.060 Script: Retrospectively logging previous script records:
< 2017-01-06 10:56:03.061 Script: Opening session using command-line parameter in scripting is deprecated. Use 'open' command instead.
. 2017-01-06 10:56:03.061 --------------------------------------------------------------------------
. 2017-01-06 10:56:03.061 Session name: C (Ad-Hoc site)
. 2017-01-06 10:56:03.061 Host name: C (Port: -1)
. 2017-01-06 10:56:03.061 User name: (Password: No, Key file: No)
. 2017-01-06 10:56:03.061 Tunnel: No
. 2017-01-06 10:56:03.061 Transfer Protocol: SFTP (SCP)
. 2017-01-06 10:56:03.061 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2017-01-06 10:56:03.061 Disable Nagle: No
. 2017-01-06 10:56:03.061 Proxy: None
. 2017-01-06 10:56:03.061 Send buffer: 262144
. 2017-01-06 10:56:03.061 SSH protocol version: 2; Compression: No
. 2017-01-06 10:56:03.061 Bypass authentication: No
. 2017-01-06 10:56:03.061 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2017-01-06 10:56:03.061 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2017-01-06 10:56:03.061 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2017-01-06 10:56:03.061 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2017-01-06 10:56:03.061 Simple channel: Yes
. 2017-01-06 10:56:03.061 Return code variable: Autodetect; Lookup user groups: Auto
. 2017-01-06 10:56:03.061 Shell: default
. 2017-01-06 10:56:03.061 EOL: LF, UTF: Auto
. 2017-01-06 10:56:03.061 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2017-01-06 10:56:03.061 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2017-01-06 10:56:03.061 SFTP Bugs: Auto,Auto
. 2017-01-06 10:56:03.061 SFTP Server: default
. 2017-01-06 10:56:03.061 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2017-01-06 10:56:03.061 Cache directory changes: Yes, Permanent: Yes
. 2017-01-06 10:56:03.061 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2017-01-06 10:56:03.061 DST mode: Unix
. 2017-01-06 10:56:03.061 --------------------------------------------------------------------------
. 2017-01-06 10:56:03.061 Looking up host "C" for SSH connection