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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: