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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-24-2004, 07:16 PM
|
#1
|
LQ Newbie
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26
Rep:
|
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!
|
|
|
11-24-2004, 07:57 PM
|
#2
|
Member
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292
Rep:
|
if its just grabbing files, look at scp. you can do that is a simple shell script...
|
|
|
11-24-2004, 08:12 PM
|
#3
|
LQ Newbie
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26
Original Poster
Rep:
|
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!
|
|
|
11-25-2004, 09:12 AM
|
#4
|
LQ Newbie
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26
Original Poster
Rep:
|
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
|
|
|
11-27-2004, 03:30 PM
|
#5
|
Member
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292
Rep:
|
oh. /proc files.... /proc files dont really exist, theyre a bit of kernel memory.
|
|
|
11-27-2004, 04:41 PM
|
#6
|
LQ Newbie
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26
Original Poster
Rep:
|
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).
|
|
|
11-27-2004, 07:22 PM
|
#7
|
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440
Rep:
|
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
|
|
|
11-28-2004, 10:04 AM
|
#8
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
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 10:07 AM.
|
|
|
11-28-2004, 12:13 PM
|
#9
|
LQ Newbie
Registered: Nov 2004
Location: Canada
Distribution: Slackware
Posts: 26
Original Poster
Rep:
|
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
......
|
|
|
All times are GMT -5. The time now is 12:56 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|