Post a reply

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)


Topic review



Well basicly 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

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.

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).

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.


@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=

"C:\Program Files (x86)\WinSCP\" /script=C:\Users\admin\Desktop\backupscript-test.txt /parameter scp://ubnt:ubnt@%HOST1%


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

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