I need help. I have Linux box (openSUSE 11.4); writing Perl script (Perl 5, version 12). My script should SSH to the remote Linux machine and get back with the memory results. So far, I have SSH working with DSA private key for passwordless connection. Now I'm stuck with getting memory.

I tried to use Filesys::DiskSpace module, but I have some trouble while installing this module. Guess it will not work.

Any help will be appreciated!

Thanks in advance!


Why bring perl into the mix? This is just a single-line deal:

$ ssh user@host free
| improve this answer | |
  • I need Perl script. It's a project requirement. My script should be sort of automatic that will run on every linux machine and get memory statistics. and memory is only first part of the project... :) – Maestro Jun 28 '11 at 20:18
  • 1
    Ahh, so this is a homework question. Well then looks like it'll get closed. Homework questions are off-topic. – EEAA Jun 28 '11 at 20:19
  • it's not homework. I just want to automate my work rutine. – Maestro Jun 28 '11 at 20:22
  • 2
    Why reinvent the wheel? There are dozens of open-source projects you can install that do this out of the box. Munin is one that I highly recommend. If you insist on a perl script, just make the above system call from within perl, storing the output in a variable. – EEAA Jun 28 '11 at 20:25
  • After searching the Internet, I realized that I cannot use Munin on the network we have here. However, it is really great software! Thanks! Because we cannot install Munin-node to other devices in the network (such as Solaris and Windows based servers). – Maestro Jun 29 '11 at 15:14

Just execute cat /proc/meminfo on the target machine to retrieve all informations about the current memory usage you could get from the system.

| improve this answer | |
  • I was thinking about writing my script so that it will trigger a command on the other remote machine and get results back. But I have no idea how to write it. – Maestro Jun 28 '11 at 20:20
  • use Net::OpenSSH to execute commands on the remote side, and simply parse /proc/meminfo, thats the easiest way you could go. Use free is another way, but its harder to parse. (just a little bit) – Thomas Berger Jun 28 '11 at 20:23
  • I also have Solaris servers on the network, so I need other specific command to get free memory available on the remote machine. Any suggestions? Thanks in advance! – Maestro Jun 29 '11 at 15:19
  • @Maestro: check also Net::OpenSSH::Parallel – salva Jun 30 '11 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.