Posts tagged ‘plink’

26/02/2011

Relative batchfile paths

In a previous post “Batch file to perform SSH commands and transfer files from Windows to Linux” I used a batchfile to call on plink.exe as follows:

C:\Path\plink.exe

This is all well and good, but if this path changes for whatever reason (i.e. you save it to another directory or machine) then it won’t work.

There is an easy fix that gives the relative path, as long as the .bat and .exe are in the same directory:

%~dp0plink.exe

Hope this proves useful.

23/11/2010

Batch file to perform SSH commands and transfer files from Windows to Linux

At my place of work, I routinely have to update firmware and database files from our office Windows PCs to ARM linux devices.

This used to involve connecting to the mini PC using PuTTY, killing a process, then logging in using an FTP client to transfer files across, finally rebooting the Linux device.

That is, until I automated the process with plink.exe and pscp.exe (available from the PuTTY download site) and a Windows batchfile:


@set /p IP="Enter the IP address of the Linux device, and press enter:"
@echo.
@echo Killing processx
@echo.
@C:\Path\plink.exe -ssh -pw password user@%IP% killall processx
@ping %IP% -n 2 -w 1000 > nul
@ping %IP% -n %1% -w 1000> nul
@echo Transferring FileX
@C:\Path\pscp.exe -scp -pw password C:\Path\FileX user@%IP%:/linux/path
@echo.
@echo Rebooting Controller at %IP%
@C:\Path\plink.exe -ssh -pw password user@%IP% reboot
@echo.
@echo Your Linux device will be back online shortly.
@echo.
@PAUSE;

In this example, you’d have to have your batch file, FileX, plink.exe and pscp.exe in the C:\Path\ directory on your Windows PC. Obviously substitute your real SSH username and password in for ‘user’ and ‘password’.