I am using following commands to extract the disk space using ssh remotely. but wants to iust store the output instead of all other message as below;

Any help? or any alternative solution?

ssh rajesh-server 'df -h /db* | cat' 2>&1

| This system is for the use of authorized users only.            |
| Individuals using this computer system without authority, or in |
| excess of their authority, are subject to having all of their   |
| activities on this system monitored and recorded by system      |
| personnel.                                                      |
|                                                                 |
| In the course of monitoring individuals improperly using this   |
| system, or in the course of system maintenance, the activities  |
| of authorized users may also be monitored.                      |
|                                                                 |
| Anyone using this system expressly consents to such monitoring  |
| and is advised that if such monitoring reveals possible         |
| evidence of criminal activity, system personnel may provide the |
| evidence of such monitoring to law enforcement officials.       |

Filesystem            Size  Used Avail Use% Mounted on
                  200G  154G   44G  79% /db01_day
                  200G  154G   44G  79% /db01_day
                  200G  154G   44G  79% /db01_day
  • ssh -q rajesh-server 'df -h /db* | cat' 2>&1 solved my problem – Rajesh Kumar Apr 26 '12 at 15:23

All of the text in the "box" is generated by your login scripts, and not by the df command. Often, a server set up with login messages will skip showing you those messages if a file called .hushlogin exists in your home directory. So first off, try creating that file:

ssh rajesh-server "touch .hushlogin"

Next, you don't need the | cat in your command line, OR the stderr redirection most likely. Try this instead:

ssh rajesh-server 'df -h /db*'

If you still get the messages with the .hushlogin file in place, then you will need to parse your output. This would do it:

ssh rajesh-server 'df -h /db*' | sed '/^|/d'

This sed command takes in the output of your ssh command, deletes any lines starting with a pipe character, and prints everything else.

Note that you probably want to consider using a monitoring tool that is build specifically for this kind of task. Many exist, some as RRDTool front-ends. My favourites are Cacti and Munin. These will graph your disk (or network or other) usage so you can see how things change over time.

If you'd like a tool that sends you a warning if you get close to limits, have a look at Nagios, Icinga or Zabbix.

| improve this answer | |
  • Hi Graham, Thank very much for your useful info. I am trying other tools as you mentioned. But could not get working any of the ssh commands tips. ;( – Rajesh Kumar Apr 18 '12 at 21:29
  • No problem, happy to help. What does "could not get working" mean, exactly? Do you get errors? I have a keyboard at home into which I spilled coffee once, so now when I press "s" I get "z". If you have a similarly damaged keyboard, it would be difficult to run either the "zzh" or "zed" commands... – Graham Apr 18 '12 at 21:35
  • I used all adove command and output is coming "|---" etc...no change in output. – Rajesh Kumar Apr 18 '12 at 21:57
  • I mean output of all adove commands are same.. – Rajesh Kumar Apr 18 '12 at 21:59
  • let me add more point is that i am using Linux RHEL – Rajesh Kumar Apr 18 '12 at 22:11
ssh rajesh-server 'df -h /db*' > file 2> /dev/null

sends the remote df output to file while sending the server's cruft to /dev/null.

| improve this answer | |
  • I am using some automation. Is it possible to display on command prompt only? – Rajesh Kumar Apr 18 '12 at 20:47

Your Answer

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