Results 1 to 2 of 2
I need a program that is written in C++, to transmit command over SSH. to Cisco equipment. every 5 hours and every 5 days. Please help me.
I'm new, you ...
- 02-26-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 1
script C++ with shh
I need a program that is written in C++, to transmit command over SSH. to Cisco equipment. every 5 hours and every 5 days. Please help me.

I'm new, you can send mail to.
luis.saavedra3@gmail.com


- 02-26-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 45
Answer:
Actually you donʼt really need C++ for that, «bash» will do just fine. I hope my pretension is forgiven when I say that I think I know what you are looking for… which is: «ssh-agent»¹.
To shortly describe «ssh-agent»:
An example script that solves a problem I think you try to solve is:Code:$> man ssh-agent […] DESCRIPTION ssh‐agent is a program to hold private keys used for public key authentication (RSA, DSA). The idea is that ssh‐agent is started in the beginning of an X‐session or a login session, and all other windows or programs are started as clients to the ssh‐agent program. Through use of environment variables the agent can be located and automatically used for authentication when logging in to other machines using ssh(1). […]
What does this code do?Code:#! /bin/bash eval `ssh-agent`; ssh-add ~/.ssh/MY_CICSO_RSA_PRIVATE_KEY; while sleep 18000; do ## 18000 seconds = 300 minutes = 5 hours ssh undisclosed_cisco_equipment.host.domain "$COMMAND"; done
- It starts the «ssh-agent»-server, which makes itself known to the world through environment variables (thus the grave accents),
- adds a private key to its memory as «ssh-add» knows how to communicate with «ssh-agent» through the just mentioned environment variables (you may need to enter a passphrase at this point if the private key in question is encrypted (which is generally a good idea)) and after this point
- each call to «ssh», which happens to occur with the same SSH related environment variables, will use the private key for logins. Thus only initialisation needs to be provided with a passphrase (if any).
In the above example the ssh call lacks any possibly neccessary CLI option and if $COMMAND is a not instantly terminating command that doesnʼt instantly close itʼs standard input and output descriptors (stdin, stdout, stderr), then the «ssh»-call will last as long as the command runs, which might not be the desired outcome. «~/.ssh/MY_CISCO_RSA_PRIVATE_KEY» had to be created beforehand, of course, using «ssh-keygen»², while the public counterpart had to exist on the to-be-connected-host in the «~/.ssh»-directory of the user whose identity you use there (i.e. through the «-l» ssh CLI option).
If this solution has to be created in C++, then you only need to translate the given example to a C++ equivalent with a lot of «fork()»s and «exec()»s.
Footnotes:


Reply With Quote