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

pioneernetworks

Okay,

Well basically what I am attempting to do is have it where I just put the IP address in and it goes through to each server and pulls the /tmp/system.cfg to E:\Backups\ipaddress.txt.timestamp
martin

Re: Variable in console script

First, you are using two different features of WinSCP to achieve one goal (passing parameters to a script), environment variables and script parameters.
While technically, it's ok, it looks bit strange and confusing.
See
https://winscp.net/eng/docs/scripting#variables
https://winscp.net/eng/docs/scripting#arguments

Anyway, the main problem is that you set variable HOST1, but you refer to HOST* in get system.cfg "E:\backup\%HOST*%.txt.%STAMP%". Replace the HOST* by HOST1.

Also note that WinSCP 5.6.x supports %TIMESTAMP% syntax that simplifies the code to:
get system.cfg "E:\backup\%HOST1%.txt.%TIMESTAMP#yyyymmddhhnnss%"
(and you do not need the for /F "usebackq ... set STAMP= ... magic).
See
https://winscp.net/eng/docs/scripting#timestamp
https://winscp.net/eng/docs/script_download_timestamped_filename#scripting
pioneernetworks

Variable in console script

I am by far not a scripting or code writer but I am attempting to backup multiple network devices (over 70). I have built two different files one called the master-backup.cmd and then the script.txt for WinSCP. I am attempting to get it to backup to a drive as ipaddress.txt.timestamp the timestamp is working correctly but the ipaddress piece is not. In the main file I want to just simply put in multiple devices and run the script. The IP address piece on the backup file I am needing to be a wildcard to change depending on the device its connected to. I have the below in the script right now.

//master-batch.cmd\\
@echo off
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%%LDT:~8,2%%LDT:~10,2%%LDT:~12,2%
set HOST1=172.16.1.20
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" /script=C:\Users\admin\Desktop\backupscript-test.txt /parameter scp://ubnt:ubnt@%HOST1%

//backupscript-text.txt\\
option batch abort
option confirm off
open %1%
cd /tmp
option transfer binary
get system.cfg "E:\backup\%HOST*%.txt.%STAMP%"
close
exit

I am attempting to get the %HOST*% to be the IP address of the host its connected to from /parameters piece. It currently saves the file as %HOSTm%.txt.20141223130100