how to repeatedly execute a command on a remote machine via a shh login from within a perl program capturing the output?

Hi,

I'm trying to repeatedly execute a command on a remote machine and
to capture the output with a perl program.

I have tried Net::OpenSSH and Net::SSH::Perl.  Both log in, execute the
command, capture the output --- and then log out.  According to the log
file of the remote machine, Net::OpenSSH logs out by closing the
connection after running the command once despite being designed
otherwise.  Net::OpenSSH is designed to log out after each command.


Since I want to execute the command repeatedly (over long periods of
time in intervals of maybe 300 seconds), I do not want to close the
connection to the remote machine until my perl program is finished.

How could this be achieved?


The purpose is to get room temperature readings which are stored in a
table in a mysql database.  I haven't found any device at a reasonable
price that would reliably provide such readings.

Using lmsensors works, but the readings are too much influenced by the
temperature of the server.  I have a switch that provides pretty stable
temperature readings which I might be able to use instead, and to get
those, I have to log in to the switch and issue a command that shows its
temperature.

Hence I don't want to log in and out all the time just to get a
temperature reading.


Suggestions for reliably getting a room temperature reading are also
welcome.  I do not want to use the serial port because I sometimes need
it to connect to a console port on a switch or router, and there's only
one serial port.  I could use the parallel port or usb, though.

I'm not really inclined to solder some sort of diy thingy myself as I'd
probably overheat the parts and do more damage than anything else; it's
just not my thing doing that kind of stuff.

If anything fails, I could get away by hooking up a simple thermostat
which opens and closes a contact depending on temperature, as long as I
can get a reading whether the contact is opened or closed.  It won't be
a good solution, yet better than nothing.

I'm aware that there are USB sticks ("temper") that /might/ work, but
from what I've been reading, they seem rather unreliable even if you can
get one to work.
0
lee
4/19/2017 1:19:37 AM
perl.beginners 29211 articles. 2 followers. Follow

11 Replies
11 Views

Similar Articles

[PageSpeed] 52

> On Apr 18, 2017, at 6:19 PM, lee <lee@yagibdah.de> wrote:
>=20
> The purpose is to get room temperature readings

Hey Lee,

	I don=E2=80=99t have a solution for you, but I have an idea that =
might help.  Have you tried the Misterhouse mailing list?  It=E2=80=99s =
a Perl script that handles sensors like that so someone there may have =
done what you=E2=80=99re trying to do.

https://sourceforge.net/p/misterhouse/mailman/misterhouse-users/

HTH,
Frank=
0
perl
4/19/2017 2:19:30 AM
Hm,  IIUC can't the remote script sleep-loop and send output
back asynchronously.  (More reseach needed on async piece)..

$ssh->system('/path/to/remote_script  arg, arg,...');

#!/bin/...
# remote_script
for (...); do  get_temp_probe(); ..... ; sleep 300; done








On Tue, Apr 18, 2017 at 6:19 PM, lee <lee@yagibdah.de> wrote:
>
> Hi,
>
> I'm trying to repeatedly execute a command on a remote machine and
> to capture the output with a perl program.
>
> I have tried Net::OpenSSH and Net::SSH::Perl.  Both log in, execute the
> command, capture the output --- and then log out.  According to the log
> file of the remote machine, Net::OpenSSH logs out by closing the
> connection after running the command once despite being designed
> otherwise.  Net::OpenSSH is designed to log out after each command.
>
>
> Since I want to execute the command repeatedly (over long periods of
> time in intervals of maybe 300 seconds), I do not want to close the
> connection to the remote machine until my perl program is finished.
>
> How could this be achieved?
>
>
> The purpose is to get room temperature readings which are stored in a
> table in a mysql database.  I haven't found any device at a reasonable
> price that would reliably provide such readings.
>
> Using lmsensors works, but the readings are too much influenced by the
> temperature of the server.  I have a switch that provides pretty stable
> temperature readings which I might be able to use instead, and to get
> those, I have to log in to the switch and issue a command that shows its
> temperature.
>
> Hence I don't want to log in and out all the time just to get a
> temperature reading.
>
>
> Suggestions for reliably getting a room temperature reading are also
> welcome.  I do not want to use the serial port because I sometimes need
> it to connect to a console port on a switch or router, and there's only
> one serial port.  I could use the parallel port or usb, though.
>
> I'm not really inclined to solder some sort of diy thingy myself as I'd
> probably overheat the parts and do more damage than anything else; it's
> just not my thing doing that kind of stuff.
>
> If anything fails, I could get away by hooking up a simple thermostat
> which opens and closes a contact depending on temperature, as long as I
> can get a reading whether the contact is opened or closed.  It won't be
> a good solution, yet better than nothing.
>
> I'm aware that there are USB sticks ("temper") that /might/ work, but
> from what I've been reading, they seem rather unreliable even if you can
> get one to work.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
0
derykus
4/19/2017 5:24:13 AM
If the temperature is available on your switch, can you not enable SNMP on =
it and read the specific OID to get the info?  Far far easier than trying t=
o keep an ssh connection open, I think.

I guess this does depend on the switch type and whether the info is availab=
le on the device via SNMP, though.

  Duncs

-----Original Message-----
From: lee [mailto:lee@yagibdah.de]=20
Sent: 19 April 2017 02:20
To: beginners@perl.org
Subject: how to repeatedly execute a command on a remote machine via a shh =
login from within a perl program capturing the output?


Hi,

I'm trying to repeatedly execute a command on a remote machine and
to capture the output with a perl program.

I have tried Net::OpenSSH and Net::SSH::Perl.  Both log in, execute the
command, capture the output --- and then log out.  According to the log
file of the remote machine, Net::OpenSSH logs out by closing the
connection after running the command once despite being designed
otherwise.  Net::OpenSSH is designed to log out after each command.


Since I want to execute the command repeatedly (over long periods of
time in intervals of maybe 300 seconds), I do not want to close the
connection to the remote machine until my perl program is finished.

How could this be achieved?


The purpose is to get room temperature readings which are stored in a
table in a mysql database.  I haven't found any device at a reasonable
price that would reliably provide such readings.

Using lmsensors works, but the readings are too much influenced by the
temperature of the server.  I have a switch that provides pretty stable
temperature readings which I might be able to use instead, and to get
those, I have to log in to the switch and issue a command that shows its
temperature.

Hence I don't want to log in and out all the time just to get a
temperature reading.


Suggestions for reliably getting a room temperature reading are also
welcome.  I do not want to use the serial port because I sometimes need
it to connect to a console port on a switch or router, and there's only
one serial port.  I could use the parallel port or usb, though.

I'm not really inclined to solder some sort of diy thingy myself as I'd
probably overheat the parts and do more damage than anything else; it's
just not my thing doing that kind of stuff.

If anything fails, I could get away by hooking up a simple thermostat
which opens and closes a contact depending on temperature, as long as I
can get a reading whether the contact is opened or closed.  It won't be
a good solution, yet better than nothing.

I'm aware that there are USB sticks ("temper") that /might/ work, but
from what I've been reading, they seem rather unreliable even if you can
get one to work.

--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
0
duncan
4/19/2017 7:45:13 AM
SSC_perl <perl@surfshopcart.com> writes:

>> On Apr 18, 2017, at 6:19 PM, lee <lee@yagibdah.de> wrote:
>>=20
>> The purpose is to get room temperature readings
>
> Hey Lee,
>
> 	I don=E2=80=99t have a solution for you, but I have an idea that might
> help.  Have you tried the Misterhouse mailing list?  It=E2=80=99s a Perl
> script that handles sensors like that so someone there may have done
> what you=E2=80=99re trying to do.
>
> https://sourceforge.net/p/misterhouse/mailman/misterhouse-users/

Thanks, I'll check that out.


(I seem to have become unsubscribed from this list and am trying to
resubscribe.)
0
lee
4/19/2017 8:04:00 AM
Duncan Ferguson <duncan.ferguson@opsview.com> writes:

> If the temperature is available on your switch, can you not enable SNMP on it and read the specific OID to get the info?  Far far easier than trying to keep an ssh connection open, I think.
>
> I guess this does depend on the switch type and whether the info is available on the device via SNMP, though.

Good idea, thanks!  I need to check the documentation if there is a way
to use SNMP for this.  I guess chances are good because it's a pretty
powerful switch :)


(I seem to have become unsubscribed from this list and am trying to
resubscribe.)
0
lee
4/19/2017 8:08:30 AM
--001a1141247e36fc02054d81250d
Content-Type: text/plain; charset=UTF-8

+1 for SNMP, or if Net::SSH::Perl didn't help, can you  try expect module?

Cheers,
Shekar

On Wed, Apr 19, 2017 at 1:38 PM, lee <lee@yagibdah.de> wrote:

> Duncan Ferguson <duncan.ferguson@opsview.com> writes:
>
> > If the temperature is available on your switch, can you not enable SNMP
> on it and read the specific OID to get the info?  Far far easier than
> trying to keep an ssh connection open, I think.
> >
> > I guess this does depend on the switch type and whether the info is
> available on the device via SNMP, though.
>
> Good idea, thanks!  I need to check the documentation if there is a way
> to use SNMP for this.  I guess chances are good because it's a pretty
> powerful switch :)
>
>
> (I seem to have become unsubscribed from this list and am trying to
> resubscribe.)
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--001a1141247e36fc02054d81250d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">+1 for SNMP, or if Net::SSH::Perl didn&#39;t help, can you=
 =C2=A0try expect module?</div><div class=3D"gmail_extra"><br clear=3D"all"=
><div><div class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><di=
v dir=3D"ltr">Cheers,<br>Shekar<br></div></div></div>
<br><div class=3D"gmail_quote">On Wed, Apr 19, 2017 at 1:38 PM, lee <span d=
ir=3D"ltr">&lt;<a href=3D"mailto:lee@yagibdah.de" target=3D"_blank">lee@yag=
ibdah.de</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">Duncan Ferguson &lt;<a href=3D"mailto:duncan.ferguson@opsview.com"=
>duncan.ferguson@opsview.com</a>&gt; writes:<br>
<br>
&gt; If the temperature is available on your switch, can you not enable SNM=
P on it and read the specific OID to get the info?=C2=A0 Far far easier tha=
n trying to keep an ssh connection open, I think.<br>
&gt;<br>
&gt; I guess this does depend on the switch type and whether the info is av=
ailable on the device via SNMP, though.<br>
<br>
</span>Good idea, thanks!=C2=A0 I need to check the documentation if there =
is a way<br>
to use SNMP for this.=C2=A0 I guess chances are good because it&#39;s a pre=
tty<br>
powerful switch :)<br>
<span class=3D"im HOEnZb"><br>
<br>
(I seem to have become unsubscribed from this list and am trying to<br>
resubscribe.)<br>
<br>
</span><div class=3D"HOEnZb"><div class=3D"h5">--<br>
To unsubscribe, e-mail: <a href=3D"mailto:beginners-unsubscribe@perl.org">b=
eginners-unsubscribe@perl.org</a><br>
For additional commands, e-mail: <a href=3D"mailto:beginners-help@perl.org"=
>beginners-help@perl.org</a><br>
<a href=3D"http://learn.perl.org/" rel=3D"noreferrer" target=3D"_blank">htt=
p://learn.perl.org/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div>

--001a1141247e36fc02054d81250d--
0
c
4/19/2017 8:52:13 AM
Shekar <c.shekar1987@gmail.com> writes:

> +1 for SNMP, or if Net::SSH::Perl didn't help, can you  try expect module?

Thanks!  'Expect' isn't available as Gentoo package, so I skipped it.

SNMP is probably better, so I need to learn about that first and see if
I can use it.  I guess it's time to learn about SNMP anyway :)


(BTW, I seem to be subscribed again :) )

>
> Cheers,
> Shekar
>
> On Wed, Apr 19, 2017 at 1:38 PM, lee <lee@yagibdah.de> wrote:
>
>> Duncan Ferguson <duncan.ferguson@opsview.com> writes:
>>
>> > If the temperature is available on your switch, can you not enable SNMP
>> on it and read the specific OID to get the info?  Far far easier than
>> trying to keep an ssh connection open, I think.
>> >
>> > I guess this does depend on the switch type and whether the info is
>> available on the device via SNMP, though.
>>
>> Good idea, thanks!  I need to check the documentation if there is a way
>> to use SNMP for this.  I guess chances are good because it's a pretty
>> powerful switch :)
>>
>>
>> (I seem to have become unsubscribed from this list and am trying to
>> resubscribe.)
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>> For additional commands, e-mail: beginners-help@perl.org
>> http://learn.perl.org/
>>
>>
>>
0
lee
4/20/2017 12:12:11 AM
lee <lee@yagibdah.de> writes:

> Shekar <c.shekar1987@gmail.com> writes:
>
>> +1 for SNMP, or if Net::SSH::Perl didn't help, can you  try expect module?
>
> Thanks!  'Expect' isn't available as Gentoo package, so I skipped it.
>
> SNMP is probably better, so I need to learn about that first and see if
> I can use it.  I guess it's time to learn about SNMP anyway :)

Ok, I got this far:


snmpget -v 3 -u lee h3c .1.3.6.1.2.1.1.3.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1081149678) 125 days, 3:11:36.78


Any idea how to get the temperature reading?
0
lee
4/20/2017 2:12:16 AM
--001a1141247e228f77054d927933
Content-Type: text/plain; charset=UTF-8

Depending upon how vendor implemented SNMP part for their device, other
than standard OID's such as sysUptime , will have custom MIB files.
You should try visiting their website for downloading required MIB file for
your switch.
Then import them with -m or put it under snmp path to get its OID's working.

Cheers,
Shekar

On Thu, Apr 20, 2017 at 7:42 AM, lee <lee@yagibdah.de> wrote:

> lee <lee@yagibdah.de> writes:
>
> > Shekar <c.shekar1987@gmail.com> writes:
> >
> >> +1 for SNMP, or if Net::SSH::Perl didn't help, can you  try expect
> module?
> >
> > Thanks!  'Expect' isn't available as Gentoo package, so I skipped it.
> >
> > SNMP is probably better, so I need to learn about that first and see if
> > I can use it.  I guess it's time to learn about SNMP anyway :)
>
> Ok, I got this far:
>
>
> snmpget -v 3 -u lee h3c .1.3.6.1.2.1.1.3.0
> DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1081149678) 125 days,
> 3:11:36.78
>
>
> Any idea how to get the temperature reading?
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--001a1141247e228f77054d927933
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Depending upon how vendor implemented SNMP part for t=
heir device, other than standard OID&#39;s such as sysUptime , will have cu=
stom MIB files.=C2=A0</div><div>You should try visiting their website for d=
ownloading required MIB file for your switch.</div><div>Then import them wi=
th -m or put it under snmp path to get its OID&#39;s working.</div><div cla=
ss=3D"gmail_extra"><br clear=3D"all"><div><div class=3D"gmail_signature" da=
ta-smartmail=3D"gmail_signature"><div dir=3D"ltr">Cheers,<br>Shekar<br></di=
v></div></div>
<br><div class=3D"gmail_quote">On Thu, Apr 20, 2017 at 7:42 AM, lee <span d=
ir=3D"ltr">&lt;<a href=3D"mailto:lee@yagibdah.de" target=3D"_blank">lee@yag=
ibdah.de</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">lee &lt;<a href=3D"mailto:lee@yagibdah.de">lee@yagibdah.de</a>&gt;=
 writes:<br>
<br>
&gt; Shekar &lt;<a href=3D"mailto:c.shekar1987@gmail.com">c.shekar1987@gmai=
l.com</a>&gt; writes:<br>
&gt;<br>
&gt;&gt; +1 for SNMP, or if Net::SSH::Perl didn&#39;t help, can you=C2=A0 t=
ry expect module?<br>
&gt;<br>
&gt; Thanks!=C2=A0 &#39;Expect&#39; isn&#39;t available as Gentoo package, =
so I skipped it.<br>
&gt;<br>
&gt; SNMP is probably better, so I need to learn about that first and see i=
f<br>
&gt; I can use it.=C2=A0 I guess it&#39;s time to learn about SNMP anyway :=
)<br>
<br>
</span>Ok, I got this far:<br>
<br>
<br>
snmpget -v 3 -u lee h3c .1.3.6.1.2.1.1.3.0<br>
DISMAN-EVENT-MIB::<wbr>sysUpTimeInstance =3D Timeticks: (1081149678) 125 da=
ys, 3:11:36.78<br>
<br>
<br>
Any idea how to get the temperature reading?<br>
<div class=3D"HOEnZb"><div class=3D"h5"><br>
--<br>
To unsubscribe, e-mail: <a href=3D"mailto:beginners-unsubscribe@perl.org">b=
eginners-unsubscribe@perl.org</a><br>
For additional commands, e-mail: <a href=3D"mailto:beginners-help@perl.org"=
>beginners-help@perl.org</a><br>
<a href=3D"http://learn.perl.org/" rel=3D"noreferrer" target=3D"_blank">htt=
p://learn.perl.org/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>

--001a1141247e228f77054d927933--
0
c
4/20/2017 5:32:35 AM
Shekar <c.shekar1987@gmail.com> writes:

> Depending upon how vendor implemented SNMP part for their device, other
> than standard OID's such as sysUptime , will have custom MIB files.
> You should try visiting their website for downloading required MIB file for
> your switch.
> Then import them with -m or put it under snmp path to get its OID's working.

Thanks!  I couldn't find them.

I always stayed away from SNMP, and now that I learned about it, it
seems a very good idea to stay away even further.  It's an awful mess.
0
lee
4/20/2017 11:31:54 PM
--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

bWFpbGluZyBsaXN0cyA8bGlzdGFzLmNvcnJlb0B5YWhvby5lcz4gd3JpdGVzOg0KDQo+IGFyZSB5
b3Ugc3VyZT8NCj4NCj4gIyBlbWVyZ2UgLXMgZXhwZWN0wqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKg
wqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDC
oMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKg
wqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDC
oMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoMKgwqAgDQo+IFsgUmVzdWx0cyBmb3Igc2Vh
cmNoIGtleSA6IGV4cGVjdCBdDQo+IFNlYXJjaGluZy4uLg0KPg0KPiBbLi4uXQ0KPiAqwqAgZGV2
LXBlcmwvRXhwZWN0DQo+IMKgwqDCoMKgwqAgTGF0ZXN0IHZlcnNpb24gYXZhaWxhYmxlOiAxLjMy
MC4wLXIxDQo+IMKgwqDCoMKgwqAgTGF0ZXN0IHZlcnNpb24gaW5zdGFsbGVkOiBbIE5vdCBJbnN0
YWxsZWQgXQ0KPiDCoMKgwqDCoMKgIFNpemUgb2YgZmlsZXM6IDYxIEtpQg0KPiDCoMKgwqDCoMKg
IEhvbWVwYWdlOsKgwqDCoMKgwqAgaHR0cDovL3NlYXJjaC5jcGFuLm9yZy9kaXN0L0V4cGVjdC8N
Cj4gwqDCoMKgwqDCoCBEZXNjcmlwdGlvbjrCoMKgIEV4cGVjdCBmb3IgUGVybA0KPiDCoMKgwqDC
oMKgIExpY2Vuc2U6wqDCoMKgwqDCoMKgIHx8ICggQXJ0aXN0aWMgR1BMLTErICkNCg0KSXQgdHVy
bmVkIG91dCB0byBiZSBzb21ldGhpbmcgZWxzZSwgaGFzIG5vdGhpbmcgdG8gZG8gd2l0aCBzc2gu
DQoNCg0KSSdtIHJlc29ydGluZyB0byBsaWJzc2ggYW5kIGRvIGl0IGluIEMuICBGb3IgdGhlIHJl
Y29yZCwgc2VlIGF0dGFjaG1lbnQNCi0tLSBpdCdsbCBuZWVkIHNvbWUgcmVmaW5lbWVudCwgYnV0
IGl0J3Mgd29ya2luZy4NCg0KDQo=
--=-=-=
Content-Type: text/x-csrc
Content-Disposition: inline; filename=sshctrl-pub.c

#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h> 
#include <unistd.h>
#include <string.h>


int interactive_shell_session(ssh_session session)
{
	ssh_channel channel;
	int rc;
	char readbuffer[1024];
	char writebuffer[512];
	int nbytes, nwritten;
	int tries = 0;

	memset(writebuffer, 0, sizeof(writebuffer));
	strcpy(writebuffer, "display environment\n");

	channel = ssh_channel_new(session);
	if (channel == NULL)
	{
		return SSH_ERROR;
	}

	rc = ssh_channel_open_session(channel);
	if (rc != SSH_OK)
	{
		ssh_channel_free(channel);
		return rc;
	}

	rc = ssh_channel_request_pty(channel);
	if (rc != SSH_OK) return rc;
	rc = ssh_channel_change_pty_size(channel, 16, 24);
	if (rc != SSH_OK) return rc;
	rc = ssh_channel_request_shell(channel);
	if (rc != SSH_OK) return rc;


	while ((tries < 4) && ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel))
	{
		nbytes = sizeof(writebuffer);
		nwritten = ssh_channel_write(channel, writebuffer, nbytes);
		if (nwritten != nbytes)
		{
			return SSH_ERROR;
		}

		nbytes = ssh_channel_read_nonblocking(channel, readbuffer, sizeof(readbuffer), 0);
		while (nbytes > 0)
		{
			if (write(1, readbuffer, nbytes) != (unsigned int) nbytes)
			{
				ssh_channel_close(channel);
				ssh_channel_free(channel);
				return SSH_ERROR;
			}

			nbytes = ssh_channel_read_nonblocking(channel, readbuffer, sizeof(readbuffer), 0);
		}
    
		if (nbytes < 0)
		{
			ssh_channel_close(channel);
			ssh_channel_free(channel);
			return SSH_ERROR;
		}

		tries++;
		// printf("\nsleeping\n");
		sleep(20);
	}

	return rc;
}


int main()
{
	ssh_session my_ssh_session;
	int rc;
	char *password;
	int verbosity = SSH_LOG_PROTOCOL;

	//
	// Open session and set options
	//
	my_ssh_session = ssh_new();
	if (my_ssh_session == NULL)
	{
		fprintf(stderr, "Error getting new session\n");
		exit(-1);
	}

	ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "switch.example.com");
	ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "user");
	// ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
	//
	// Connect to server
	//
	rc = ssh_connect(my_ssh_session);
	if (rc != SSH_OK)
	{
		fprintf(stderr, "Error connecting to remote host: %s\n", ssh_get_error(my_ssh_session));
		ssh_free(my_ssh_session);
		exit(-1);
	}

	//
	// Authenticate ourselves
	//
	password = "secret";
	rc = ssh_userauth_password(my_ssh_session, NULL, password);
	if (rc != SSH_AUTH_SUCCESS)
	{
		fprintf(stderr, "Error authenticating with password: %s\n", ssh_get_error(my_ssh_session));
		ssh_disconnect(my_ssh_session);
		ssh_free(my_ssh_session);
		exit(-1);
	}

	interactive_shell_session(my_ssh_session);
	fprintf(stderr, "\nError: %s\n", ssh_get_error(my_ssh_session));
	/* show_temperature(my_ssh_session); */

	ssh_disconnect(my_ssh_session);
	ssh_free(my_ssh_session);

	exit(0);
}

--=-=-=--
0
lee
4/21/2017 2:05:16 AM
Reply: