Topic "Variable in console script"

Author Message
[View user's profile]

Joined: 2014-12-23
Posts: 2
Location: United States
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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24759
Location: Prague, Czechia
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).
[View user's profile]

Joined: 2014-12-23
Posts: 2
Location: United States

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

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License