Posts tagged ‘ARM Linux’

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

Advertisements
14/11/2010

PDO/SQLite connection

I have been working for a while on a project involving running a PHP web application on on an ARM linux mini PC. There was an existing application on the PC whose SQLite database I needed to manipulate, to feed new values into the program from a web interface. The hardest thing by far was cross-compiling PHP to run in the ARM environment to include --enable-pdo --with-pdo-sqlite, but that would take too long to go into here.

I was able to collect and display data from the SQLite database using the following PHP code:

$connect = new PDO("sqlite:/path/to/sqlite.db");

$sql = "SELECT * FROM sqlite_table";

foreach ($connect->query($sql) as $info)
{
$val1=$info['val1'];

$val2=$info['val2'];
}

echo "$val1";

Tags: , , ,