LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-24-2004, 08:16 PM   #1
iago
LQ Newbie
 
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26

Rep: Reputation: 15
Running commands over ssh


I need to write a small C program on Linux that'll connect to my other server and grab some info from other files. Is there any easy way to set up a ssh connection in C that'll look after this, or would it be easier to actually call out to the "ssh" program and work through that?

Thanks for any help!
 
Old 11-24-2004, 08:57 PM   #2
m00t00
Member
 
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292

Rep: Reputation: 30
if its just grabbing files, look at scp. you can do that is a simple shell script...
 
Old 11-24-2004, 09:12 PM   #3
iago
LQ Newbie
 
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26

Original Poster
Rep: Reputation: 15
Well, I need to pull out some status information from the other computer (/proc/cpuinfo, and stuff), I need to keep track of load and such. But I can make a call out to scp from the C program to get the files, do the analysis, and remove them. That'll work great!

Thanks!
 
Old 11-25-2004, 10:12 AM   #4
iago
LQ Newbie
 
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26

Original Poster
Rep: Reputation: 15
Hmm, apparently I can't do "scp othercomputer:/proc/cpuinfo ." -- it comes over as "0" bytes, the file isn't generated.

Anybody else else know how I can pull over a snapshot of these files?

Thanks
 
Old 11-27-2004, 04:30 PM   #5
m00t00
Member
 
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292

Rep: Reputation: 30
oh. /proc files.... /proc files dont really exist, theyre a bit of kernel memory.
 
Old 11-27-2004, 05:41 PM   #6
iago
LQ Newbie
 
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26

Original Poster
Rep: Reputation: 15
I know that. But when you run a command on it, like cat, it outputs the appropriate content, which can be redirected into a file. I was hoping there'd be a way to copy them over the network easily, so I can analyze them remotely. It's sounding like it's going to be a lot of trouble.

I'm thinking I should run a server remotly that serves up the info on request, rather than fetching it. It's not a big deal if anybody who can connect to the server can get the info off it, it's nothing important (I want to be able to get info such as cpu usage, etc. on my network computers).
 
Old 11-27-2004, 08:22 PM   #7
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
why not ssh into the remote computer, cat all the files you need and redirect them to a text file, and then scp that file to your local machine (all done with a simple script). That's what I would do.

-twantrd
 
Old 11-28-2004, 11:04 AM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
you could use :
Code:
cat /proc/cpuinfo | ssh <remotehost> "cat > cpuinfo"
Then cpu infos should be in the cpuinfo file in the remote host home directory

or :
Code:
ssh <remotehost> "cat /proc/cpuinfo" > cpuinfos
The cpu infos from remote host are written in the local file cpuinfos in current directory

Last edited by Cedrik; 11-28-2004 at 11:07 AM.
 
Old 11-28-2004, 01:13 PM   #9
iago
LQ Newbie
 
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Cedrik
Code:
ssh <remotehost> "cat /proc/cpuinfo" > cpuinfos
THAT is perfect. I didn't know you could do that! Thanks a bunch!

Code:
iago@Slayer:~$ ssh darkside "cat /proc/cpuinfo" > cpuinfos
iago@Slayer:~$ cat cpuinfos | head
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 8
model name      : AMD-K6(tm) 3D processor
stepping        : 0
......
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python commands over ssh Kedelfor Programming 7 10-18-2005 05:07 AM
Passing commands via ssh Comatose51 Linux - Security 1 04-13-2005 05:31 PM
executing multiple commands by ssh jpan Linux - General 1 10-22-2004 03:12 PM
does ssh have commands similar to ftp? xviddivxoggmp3 Linux - Software 2 07-14-2004 07:04 PM
running commands automatically via SSH tpfraz Linux - General 1 02-13-2004 10:12 AM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration