I've come across a bash script which finds out memory, CPU usage etc. on remote machines. To do that it uses a technique like this:


TOTALMEM=`on $i cat /proc/meminfo | grep MemTotal | awk -F ' ' '{print $2}' `

I have searched in internet and it looks like all are using ssh username@RemoteServerName to achieve this. I am not understanding how this "on" works. The script works fine, but when I execute the command outside the script, it says: -bash: on: command not found..

I have searched in man pages, nothing found. Also, I have searched for any aliases that "on" stands for using command "type on". But nothing is found. Please help me understanding how this "on" works to execute commands on remote machines. I don't think there's a command called "on". Please help.

Both the local and remote machines are Redhat 6.2

closed as off-topic by Gilles, Jeff Schaller, Rui F Ribeiro, Stephen Kitt, GAD3R Dec 23 '16 at 8:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Gilles, Jeff Schaller, Rui F Ribeiro, Stephen Kitt, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    It may be local, or it may be defined by the site you got the script from. – Jeff Schaller Dec 22 '16 at 0:07
  • Can you edit the script to add the type on just before the TOTALMEM line? In addition to it being a command or an alias it might be a shell function, defined in either this script or in a file which is sourced by this script. – icarus Dec 22 '16 at 3:51
  • Thank you guys for your reply. My bad, it was my mistake not to search outside root's environment. I have added the update as an edit to the original question. Thanks again. – Vinod Dec 22 '16 at 21:45
  • @roaima sure. Have corrected my mistake and posted my solution as an answer. Thanks for correcting me. – Vinod Dec 22 '16 at 21:54

I found it. All I did initially was searching everywhere in my (root's) environment for an alias called "on". But then I checked how this script is being used in the server. It is used to generate hourly resource utilization of many other remote servers. So it should be a part of crontab. Yes, there we got it! This script is part of a user specific crontab of another user (non root).

There were these lines in the script:

export PATH

That user's ~/bin has the executable "on" which has all the required code to convert on $i to ssh servername.

If you are wondering why this extra step instead of directly using ssh servername, here is the explanation. The code format that I showed above was just a format and in the actual script it is used to generate reports of many servers (which are grouped into several groups) like below:

for i in $GROUP1 $GROUP2 $GROUP3
   TOTALMEM=`on $i cat /proc/meminfo | grep MemTotal | awk -F ' ' '{print $2}' `
   #other report generation and formatting code here

GROUP1, GROUP2 etc. are lists containing hostnames of similar servers.

Servers belonging to one group have common credentials for logging in. File "on" contains all the required code to form the command ssh username@servername based on their group, using case statement.

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