Hello,
I have to power off equipment like NAS and PC by using SSH command.
Could you confirm that we dont have library to connect and send to “other” equipments SSH order?
We have to use LINUX part of PFC200 PLC
there is one problem:
we can connect to other device using app
ssh -o StrictHostKeyChecking=no root@ipaddress 'command'
but you have to write the password for security reasons. No password, no problem (except security )
To send a password you need sshpass app, so you can send password:
sshpass -p 'password' ssh user@remote_ip 'command'
To do that, you can create some docker container and call it using SysProcess library or WagoAppConfigTool (SSH command from CoDeSys - #4 by WagoDamRud)
Thanks for your celerity
But i am old (ladder code generation) and i want to be sure to understand.
I will use WagoAppConfigTool to send to a NAS(IP@ 192.168.1.18) login: admin password:toto the order poweroff.
VAR
myFbConfigTool : FbConfigTool;
sResult : STRING(255);
END_VAR
myFbConfigTool( xExecute := TRUE,
sCallString := ‘sshpass -p toto ssh admin@192.168.1.18 poweroff’,
sResultString => sResult );
IF myFbConfigTool.xDone THEN
myFbConfigTool.xExecute := FALSE;
END_IF
Am i too optimist?
Okey, the codesys part is almost done, you know how to call config tool script
but you have to do some steps before.
-
Can do it only with PFC200 G2 (750-821x) or CC100 or EC or TP600 controller (linux based controllers) with Internet connection (DNS, Gateway, actual time are needed)
-
Go to WBM (https://plc_ip/wbm) > Configuration > Docker and enable it
-
Download PuTTY ( Download PuTTY - a free SSH and telnet client for Windows) it is a SSH client, so we can connect do PLC console via SSH
-
Login with root/wago
BUILD OWN CONTAINER
- youre now in /root catalog lets create folder for our solution
mkdir sshpass
cd sshpass
- Create file with instruction to create small Docker container with sshpass application
nano dockerfile
- Paste this (copy from here and right mouse click in Putty to paste)
FROM arm32v7/alpine:latest
RUN apk add --update --no-cache sshpass openssh
ENTRYPOINT ["sshpass"]
CMD ["-h"]
And press CTRL+x, then Y and enter
-
Build you own image
docker build -t sshpass-arm7 .
The dot is important
The output will show something like:
-
Now you can call you query!
docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'
USE MY CONTAINER
- Just call:
docker run --rm -it damrudwago/sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"
And in below instruction change everywhere image name:
sshpass-arm7 → damrudwago/sshpass-arm7
Okey, but this script command is quite long, so you can make an ALIAS
alias yournameofthecommandhere="docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"
so now you can just call:
yournameofthecommandhere
to run your power off command!
Now you can use SysProcess to call it directly or in /etc/config-tools/ create new script to use WagoAppConfigTool:
nano /etc/config-tools/myscript1
Paste:
!#/bin/bash
docker run --rm -it sshpass-arm7 -p 'toto' ssh -o StrictHostKeyChecking=no admin@192.168.1.18 'poweroff'"
Add permission to execute your script:
chmod +x /etc/config-tools/myscript1
Now you can call it from your Codesys application:
VAR
myFbConfigTool : FbConfigTool;
sResult : STRING(255);
END_VAR
myFbConfigTool( xExecute := TRUE,
sCallString := ‘./myscript1’,
sResultString => sResult );
IF myFbConfigTool.xDone THEN
myFbConfigTool.xExecute := FALSE;
END_IF
Thanks Damien.
i wil try it
Alpine was good this weekend, it is a good sign!
the rain shows the class of the drivers #F1
I pushed this image to my DockerHub repository, so you can use the “USE MY CONTAINER” solution which is faster then building your own image