Howto Manage More Than One Device

From Phobos Wiki
Revision as of 09:45, 29 October 2013 by Roland (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Here we explain how to manage multiple devices on Microsoft Windows. These scripts are provided as a starting point for administrators managing Martem devices in bulk. You can allways create your own, copy paste scripts found here or, just look at gws.exe "SSH Log" as a starting point.

In order to use these scripts you need to download plink.exe, pscp.exe and 7za.exe. It is assumed that these exe files are located in the same folder as scripts presented here.

Ping All

First lets see if all device are on the wire. For this it is easy to use ping utility. This script:

@echo off
start cmd /k ping 10.0.0.35 -t -w 2000
start cmd /k ping 10.0.0.36 -t -w 2000
start cmd /k ping 10.0.0.99 -t -w 2000

starts three windows and starts to ping in each window different host. In this case line 2 starts a window for 10.0.0.35, line 3 starts a window for 10.0.0.36 and in line 4 starts a window for 10.0.0.99. If you want to add more hosts add lines after:

@echo off

.

Get Setups

Now that we know who is on the wire it is time to backup setups. For this there are two scripts. First one is ReadSetup.bat:

@echo off

echo Check for arguments

if "%1" == "" ( 
	goto usage
)

if "%2" == "" ( 
	goto usage
)

if "%3" == "" ( 
	goto usage
)

if "%4" == "" ( 
	goto usage
)

set RTU_ADDR=%1
set USER_NAME=%2
set USER_PW=%3

set DATETS=%date%
set TIMETS_IN=%time%
set TIMETS=%TIMETS_IN: =0%
set YEAR=%DATETS:~-4,10%
set MDAY=%DATETS:~2,2%
set MONTH=%DATETS:~-7,2%
set HOUR=%TIMETS:~0,2%
set MIN=%TIMETS:~3,2%
set SEC=%TIMETS:~6,2%

set SETUP_FILE_PREFIX=%4-%YEAR%.%MONTH%.%MDAY%-%HOUR%.%MIN%.%SEC%

echo Get configuration for RTU at %RTU_ADDR%

echo Get gwSetup.bin and save it to %SETUP_FILE_PREFIX%_gwSetup.bin
pscp.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR%:/usr/local/etc/telem/gwSetup.bin %SETUP_FILE_PREFIX%-gwSetup.bin

echo Get setup.tar.xz and save it to %SETUP_FILE_PREFIX%_setup.tar.xz
pscp.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR%:/usr/local/etc/telem/setup.tar.xz %SETUP_FILE_PREFIX%-setup.tar.xz

echo Done reading from RTU

exit /b
pause

:usage
echo All arguments were not specified. Print the usage information.
echo Usage: %0 rtu_ip_addr user pw setupfile_name
echo Example: %0 192.168.0.111 martem Xooviet0 MyDevice
pause
exit /b

This script expects four arguments: IP address, SSH username and password and prefix to identify the saved file. ReadSetup.bat is called from unother script where IP addresses and etc are specified. For instance:

@echo off
start cmd /k ReadSetup 10.0.0.99 martem Xooviet0 GW6_10.0.0.99
start cmd /k ReadSetup 10.0.0.35 martem Xooviet0 GW6e_10.0.0.35
start cmd /k ReadSetup 10.0.0.36 martem Xooviet0 GW6e_10.0.0.36

reads setups for three devices in addresses 10.0.0.99, 10.0.0.35 and 10.0.0.36. On file system you get version 3 and version 4 files, for instance:

GW6_10.0.0.99-2013.10.29-08.58.18-gwSetup.bin
GW6_10.0.0.99-2013.10.29-08.58.18-setup.tar.xz

Saved files are in the format prefix-DATE-AND-TIME-gwSetup.bin for version 3 and prefix-DATE-AND-TIME-setup.tar.xz for version 4

Get Version

To get the firmware information there are two scripts ReadVersion.bat:

@echo off

echo Check for arguments

if "%1" == "" ( 
	goto usage
)

if "%2" == "" ( 
	goto usage
)

if "%3" == "" ( 
	goto usage
)

if "%4" == "" ( 
	goto usage
)

set RTU_ADDR=%1
set USER_NAME=%2
set USER_PW=%3

set DATETS=%date%
set TIMETS_IN=%time%
set TIMETS=%TIMETS_IN: =0%
set YEAR=%DATETS:~-4,10%
set MDAY=%DATETS:~2,2%
set MONTH=%DATETS:~-7,2%
set HOUR=%TIMETS:~0,2%
set MIN=%TIMETS:~3,2%
set SEC=%TIMETS:~6,2%

set SETUP_FILE_PREFIX=%4-%YEAR%.%MONTH%.%MDAY%-%HOUR%.%MIN%.%SEC%

echo Get version info from RTU at %RTU_ADDR%

echo Get firmware.html and save it to %SETUP_FILE_PREFIX%_firmware.html
pscp.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR%:/var/www/firmware.html %SETUP_FILE_PREFIX%-firmware.html

echo Done reading from RTU

exit /b
pause

:usage
echo All arguments were not specified. Print the usage information.
echo Usage: %0 rtu_ip_addr user pw version_file
echo Example: %0 192.168.0.111 martem Xooviet0 MyDevice
pause
exit /b

and GetVersion.bat

@echo off
start cmd /k ReadVersion 10.0.0.35 martem Xooviet0 GW6e_10.0.0.35
start cmd /k ReadVersion 10.0.0.36 martem Xooviet0 GW6e_10.0.0.36
start cmd /k ReadVersion 10.0.0.99 martem Xooviet0 GW6_10.0.0.99

ReadVersion.bat takes four arguments IP, SSH username and password and prefix. Files are saved with similar format as setup. For instance:

GW6_10.0.0.99-2013.10.29-09.00.22-firmware.html
GW6e_10.0.0.35-2013.10.29-09.00.22-firmware.html
GW6e_10.0.0.36-2013.10.29-09.00.22-firmware.html

Note that this works even if the web server is not enabled.

Update Software

To update firware use UpdateFirware.bat:

echo off

echo Check for arguments

echo %1

if "%1" == "" ( 
	goto usage
)

if "%2" == "" ( 
	goto usage
)

if "%3" == "" ( 
	goto usage
)

if "%4" == "" ( 
	echo WARNING: using default firmware file
	set FIRMWARE=Telem-GW6e_2013.05.06-next-18-80d8857-spirit-dirty_VMX53.7z
) else (
	set FIRMWARE=%4
)

set RTU_ADDR=%1
set USER_NAME=%2
set USER_PW=%3

title Firmware file:%FIRMWARE%

rmdir /S /Q %RTU_ADDR%
mkdir %RTU_ADDR%
cd %RTU_ADDR%

echo Extract %FIRMWARE%
..\7za x ..\%FIRMWARE%

echo Remove old files from RTU
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% rm -R gwupdtmp
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% rm done
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% rm -R gwupd_done
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% rm -R gwupd

echo Make gwupd directory
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% mkdir gwupdtmp

echo Copy %FIRMWARE% to RTU
..\pscp.exe -pw %USER_PW% -r gwupd\* %USER_NAME%@%RTU_ADDR%:gwupdtmp

echo Move gwupdtmp to gwupd
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% mv gwupdtmp gwupd

echo Rebooting to complete update
..\plink.exe -pw %USER_PW% %USER_NAME%@%RTU_ADDR% touch /var/local/telem/reboot

:done
cd ..
echo Remove %RTU_ADDR%
rmdir /S /Q %RTU_ADDR%
pause
exit /b

:usage
echo All arguments were not specified. Print the usage information.
echo Usage: %0 rtu_ip_addr user pw firmware_file
echo Example: %0 192.168.0.111 martem Xooviet0 kernel_1204-stable_144_154.7z
pause
exit /b

and UpdateFirmwareAllRTUs.bat:

@echo off

start cmd /k UpdateFirmware.bat 10.0.0.99 martem Xooviet0 Telem-GW6_2013.10.24-next-27-1ebcb10_PXA270.7z
start cmd /k UpdateFirmware.bat 10.0.0.35 martem Xooviet0 Telem-GW6e_2013.10.24-next-27-1ebcb10_VMX53.7z
start cmd /k UpdateFirmware.bat 10.0.0.36 martem Xooviet0 Telem-GW6e_2013.10.24-next-27-1ebcb10_VMX53.7z

updates firware for three hosts at 10.0.0.99, 10.0.0.35 and 10.0.0.36. For firware upgrading you need to know the device architecture. You can get it from version file. For instance for 10.0.0.99 it is:

<html><head><title>Martem Telem-GWM - Firmware</title></head><body>
<p>Telem-GW6 PXA270 2013.10.24-next-27-1ebcb10</p>
<p>Packed at Thu Oct 24 19:40:07 EEST 2013 on spirit</p>
<p>Linux telem-gw6 2.6.27.58-martem-2013.10.24-27 #17 PREEMPT Thu Oct 24 19:39:26 EEST 2013 armv5tel GNU/Linux</p>
<p>Telem-GW-git: 1ebcb103c13cbe806eecbb22efbc20587950556f</p>
<p>GwLinux-git: c3ab4239aa90965a7793894534b4702d508ca527</p>
<p>2013.02-04643-g6c8b059</p>
</body></html>

and for 10.0.0.35 it is:

<html><head><title>Martem Telem-GWM - Firmware</title></head><body>
<p>Telem-GW6e VMX53 2013.10.28-next-02-dcfb300-spirit-dirty</p>
<p>Packed at Mon Oct 28 14:32:18 EET 2013 on spirit</p>
<p>Linux telem-gw6e 2.6.35.3-martem-2013.10.28-2-g9e98d49 #4 PREEMPT Mon Oct 28 14:32:01 EET 2013 armv7l GNU/Linux</p>
<p>Telem-GW-git: dcfb300502f1fed9eb12f221c73e7eb490040e2e-dirty</p>
<p>GwLinux-git: ddc6ee0be932baafa76a4c0b28033d690ab595ba-dirty</p>
<p>2013.02-04643-g6c8b059</p>
</body></html>

10.0.0.99 is old GW6 with ARMv5 CPU on PXA270 board and 10.0.0.35 is newer with ARMv7 on VMX53 board.