nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Shell script to check the disk space on remote systems

This is a discussion on Shell script to check the disk space on remote systems within the Shell scripting forums, part of the Development/Scripting category; Hi, I would like to write an shell script on linux(bash), which would check the disk space on remote systems ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 06-19-2007, 11:07 PM
Junior Member
User
 
Join Date: Jun 2007
My distro: Debian
Posts: 2
Rep Power: 0
vijayscripts is on a distinguished road
Thumbs up Shell script to check the disk space on remote systems

Hi,

I would like to write an shell script on linux(bash), which would check the disk space on remote systems and allow to build if the free space is more than 70%.
can any one wirte a script for the same.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-20-2007, 12:14 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Pretty simple if remote server runs ssh server all you have to do is ssh into box and login using SSH keys and run df command:
Code:
ssh user@remote-server.ip.com df
First step is setup - SSH Public key based authentication - Howto | nixCraft

Second step is modify script - Shell script to watch the disk space | nixCraft

Here is modified script, make sure you setup ssh username and IP/hostname:
Code:
#!/bin/bash
ADMIN="me@somewher.com"
ALERT=70
ssh user@ip-address.com df -H  > /tmp/df.out
cat /tmp/df.out | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | 
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 06-20-2007, 09:33 PM
Junior Member
User
 
Join Date: Jun 2007
My distro: Debian
Posts: 2
Rep Power: 0
vijayscripts is on a distinguished road
Default

Vivek,

Thanks for the script, it was perfect,but now my boss reliased that he want the processes running on remote systems and not the disk free space.

Actually I wanted to use dmake on remote systems,so when i execute the script it need to check the processes running and the cpu occupied. so that the dmake can be performed.

Currently the dmake is failing on some of the remote systems if the cpu occupied is crossing certian limit.

please do help me on this too.
Reply With Quote
  #4 (permalink)  
Old 06-20-2007, 11:10 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Logic is same so just write out your own script
__________________
May the force with you!
Reply With Quote
  #5 (permalink)  
Old 10-20-2007, 09:38 PM
Junior Member
User
 
Join Date: Sep 2007
My distro: CentOS
Posts: 12
Rep Power: 0
vivekv is on a distinguished road
Default

I used this php file

<?php
$a = shell_exec('df -h');
echo $a;
?>


Any idea how to display it i order ?


Thanks
Reply With Quote
  #6 (permalink)  
Old 10-21-2007, 07:29 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

May be try out
Code:
 <?php
 $a = shell_exec('df -h');
echo '<h2>Disk space</h2><pre>';
echo $a;
echo '</pre>';
 ?>
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux check disk error raj Linux hardware 3 12-07-2007 11:00 AM
Shell script to perform operation on remote server vivekv Shell scripting 3 10-24-2007 01:10 AM
Linux Shell script to mount remote windows share angelus_kit Shell scripting 2 09-06-2007 08:18 PM
Shell script to monitor remote local http or port 80 amigo28 Shell scripting 1 02-12-2007 10:58 PM
shell script to open log files and check for faults trueman82 Shell scripting 1 11-23-2006 03:35 AM


All times are GMT +5.5. The time now is 05:57 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36