38,760
edits
(Updating to match new version of source page) |
(Updating to match new version of source page) |
||
Line 73: | Line 73: | ||
{{Command|ssh robot /usr/bin/ls}} | {{Command|ssh robot /usr/bin/ls}} | ||
{{Command|rsync -a datadir/a robot:scratch/testdata}} | {{Command|rsync -a datadir/a robot:scratch/testdata}} | ||
= Automation using Python and Paramiko = | |||
If you are using the [https://www.paramiko.org/index.html Paramiko Python module] to automate your workflow, this is how you can make it work with the robot nodes: | |||
<source lang=python> | |||
# ==================================================================================================== | |||
#! /usr/bin/env python3 | |||
# ==================================================================================================== | |||
import os | |||
import paramiko | |||
# ==================================================================================================== | |||
key = paramiko.Ed25519Key.from_private_key_file("/home/username/.ssh/cc_allowed") | |||
user = "username" | |||
host = "robot.graham.alliancecan.ca" | |||
ssh = paramiko.SSHClient() | |||
# If the host is not known, it is OK. | |||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |||
ssh.connect(hostname=host, username=user, pkey=key) | |||
cmd = "ls -l" | |||
stdin, stdout, stderr = ssh.exec_command(cmd) | |||
print("".join(stdout.readlines())) | |||
ssh.close() | |||
# ==================================================================================================== | |||
</source> | |||
This code connects to the robot node on '''Graham''' using an automation key specified in CCDB and | |||
executes the <code>ls -l</code> command to get the list of files. | |||
Then prints the list to the screen. | |||
Note, that it is important to install '''paramiko''' with the | |||
$ pip install paramiko[all] | |||
command. This will make sure that the support for the '''Ed25519''' key type will also be installed. |