0

I am on an effort to sending pseudo-filesystem to other machine.

In this case, I am using /proc/cpuinfo and /proc/meminfo as the pseudo-filesystem example.

I have two computer that can communicate each other in ssh.

Now, I am trying to build an *.sh code to secure copy some system file from other computer. The code was:

#INPUT
export MASTER=user@11.1.111.11
export HELPER=user@12.1.122.12


#Obtaining CPU and Memory Data
scp $MASTER:/proc/cpuinfo /master/.
scp $MASTER:/proc/meminfo /master/.
scp $HELPER:/proc/cpuinfo /helper/.
scp $HELPER:/proc/meminfo /helper/.

The idea is that I can run this script in any computer (either Master or Helper computer).

However, later on the copied files are blank and has no information inside. I try to sudo chmod and sudo chown the /proc/ folder but the system said permission denied. FYI, I do not activate root user and just using sudo all the time.

Can anybody guide me to some solutions please?

Additional info and improvisation: The full code is in jsfiddle. I am just trying to use collaboration option by jsfiddle though this code is not a JavaScript. http://jsfiddle.net/santosasandy/sWYLL/#&togetherjs=hCO3VuPwO4

Santosa Sandy
  • 217
  • 6
  • 20
  • 1
    do a test to see if something simple (not using ssh) works. like `cp /proc/cpuinfo /tmp/master`. If that doesn't work, the scp version will never work. Good luck. – shellter Feb 10 '14 at 16:56
  • Hi @shellter thank you. Yes indeed the `ssh` works properly. I can do `scp` for other file without being asked a password. I am wondering why I can not copy `/proc/cpuinfo` and `/proc/meminfo` – Santosa Sandy Feb 10 '14 at 17:08
  • @shellter Sorry for miss read your comment. I do your suggestion. I can copy it to `tmp` folder. The copied file has information (not blank). However I can not transfer it to other computer (Master to Helper or vice versa ) – Santosa Sandy Feb 10 '14 at 17:18
  • 1
    It the idea that /proc is a pseudo-filesystem is causing your problem. I think you'll have to `cp /proc/cpuinfo /tmp/master.cpuinfo ; scp /tmp/master.cpuinfo remote:/path/to/master.cpuinfo`. Good luck. – shellter Feb 10 '14 at 17:41
  • Thank you @shellter . The pseudo-filesystem makes me problem. I will think about the solution how to make a code for transferring that such a file – Santosa Sandy Feb 10 '14 at 17:44

2 Answers2

2

It appears that scp first uses stat to determine the size of the file being transferred, and then transfers up to that number of bytes. Because /proc is a pseudo-filesystem, and /proc/cpuinfo is a pseduo-file, stat reports its size as zero bytes. Therefore, scp transfers nothing.

In contrast, cp appears to just read blocks from the file until it can read no more, so the zero size reported by stat is irrelevant.

To copy the file to another system it seems you'll have to first use cp to make a local copy, and then use scp to transfer over the network.

Eric Melski
  • 16,432
  • 3
  • 38
  • 52
  • Thank you for your suggestion, Eric. @shellter also suggest the same approach. However, do you have an idea on how to execute cp from another machine? Suppose that I am on Master and I want the code to do a `cp` in Helper machine from Helper `/proc/cpuinfo` – Santosa Sandy Feb 10 '14 at 18:08
  • 1
    Highly probable theory about `stat`. Thanks for sharing. Good luck to all. – shellter Feb 10 '14 at 18:42
1

You can use cat to read from the pseudo files, instead of trying to copy them. For example:

ssh $MASTER 'cat /proc/cpuinfo' > /master/cpuinfo
chepner
  • 497,756
  • 71
  • 530
  • 681