Shell script to find filesystem capacity on 50 servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to find filesystem capacity on 50 servers
# 1  
Old 05-20-2011
Shell script to find filesystem capacity on 50 servers

Hi all,
I am new to Unix and I want to write a shell script in a jumpbox for finding the filesystem capacity on 50 unix servers ( by ssh ) and then email the result in HTML format with server name and capacity % to a specific outlook distribution list.

any suggestion would be of great help.
# 2  
Old 05-20-2011
We won't be able to write the entire script for you. We will give the key idea and you can develop on it.

First executing a command in the remote server.

Code:
cgi@tioman> (/home/cgi) $ ssh cgi@123.122.32.22 -C "df -h"
The authenticity of host '123.122.32.22 (123.122.32.22)' can't be established.
RSA key fingerprint is 72:a9:6d:a6:1b:fc:51:bf:06:bd:7f:35:2c:93:61:ee.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '123.122.32.22' (RSA) to the list of known hosts.
Password:
Filesystem             size   used  avail capacity  Mounted on
/dev/md/dsk/d30         18G    13G   4.8G    74%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.5G   1.3M   1.5G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
fd                       0K     0K     0K     0%    /dev/fd
/dev/md/dsk/d34        9.3G   3.7G   5.5G    40%    /var
swap                   1.5G   2.9M   1.5G     1%    /tmp
swap                   1.5G    40K   1.5G     1%    /var/run
/dev/md/dsk/d5          65G    22G    42G    35%    /data
/dev/md/dsk/d33        2.9G   1.1G   1.7G    40%    /home
cgi@tioman> (/home/cgi) $

To avoid typing password, you can use ssh keys.

Sending mails can be done using mailx command or anyother mail utilities. First of all, you try to get the information from all your servers.
1. make a text file which will have list of the servers.
2. Try to establish ssh key authentication between your machine to all servers.
3. Loop through the server list and execute the ssh command and store the output in a file.
4. Mail the file.
This User Gave Thanks to kumaran_5555 For This Post:
# 3  
Old 05-28-2011
@Kumar : below is the code of my script-
Code:
vtierfile=/home/m69642/vtierlist.txt
i=0
#################array of servers/usage######################
for server in `cat $vtierfile`;
do
  vtier[$i]=$server
  echo server=${vtier[$i]
  usage[$i]=`sshcmd -u ${vtier[$i]} -s ${vtier[$i]} df -k . | awk '{ print $5 " " $6 }' | cut -d " " -f1|tail -1`
  echo ${usage[$i]}
  i=$i+1
done

Output :
Code:
server=server1
server=server2
server=server3
server=server4

but it is not giving proper result.

Last edited by Scott; 05-28-2011 at 12:45 PM.. Reason: Please use code tags
# 4  
Old 05-30-2011
Can you whether the following part is working fine at your prompt.
I couldn't check that part as sshcmd isn't installed in my pc.

Code:
sshcmd -u ${vtier[$i]} -s ${vtier[$i]} df -k . | awk '{ print $5 " " $6 }' | cut -d " " -f1|tail -1

If it doesn't work may we could try a different solution.
This User Gave Thanks to kumaran_5555 For This Post:
# 5  
Old 05-31-2011
thnks a lot Kumar....
I got my desired result..
can you also please guide me how to send the result which is stored in an array to email in html foemat...I know the email part..but not quite familiar with html part...
for example I want my result in email as:

server name disk usage
server1 40%
server2 30%
server3 10%

like this....
your help would be highly appreciated...
# 6  
Old 05-31-2011
Write your normal html format with some sample content in a notepad and post here.

Then we will see how to convert the output into that html using a script.

Something like below
Code:
<html>
<body>

<h1>Server 1</h1>
<h2>Disk one</h2>

</body>
</html>

We need the html template you wanted to use
# 7  
Old 05-31-2011
post your final code and and the output, which you are getting.. we will help you to create a html report
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find Error: rpmdb open failed on list of servers

Hello all, I have a task to patch red hat servers and some servers have a corrupted rpm database and return the error: Error: rpmdb open failed I know how to fix this when it occurs. What I'm hoping to do is scan a list of servers by IP and report back which server have this error. ... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

Filesystem alert shell script not working!!

Hi All, My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert: Code: #!/bin/bash export DBALIST="abc@xyz.com" df -k /oradata/xyz/archive > dfk.result archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4` if... (6 Replies)
Discussion started by: harveyclayton
6 Replies

3. UNIX for Dummies Questions & Answers

Need a shell script to find 0 byte files in 5 servers

Hi..... Thanks for this wonderful forum.... My request: I have toatally 5 unix servers in which many applications are working I need to set a trap to identify 0 byte files if any are created proactively. For example: find /apps/fresco/ -mtime 1 -size 0c –print >>... (3 Replies)
Discussion started by: ChandruBala73
3 Replies

4. Homework & Coursework Questions

Disk Capacity Shell Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! I am pretty close I think, but stuck. I don't know how to send an email to the user specified on the command line, and I receive an error stating -ge expecting a unary value(lines... (14 Replies)
Discussion started by: polyglot0727
14 Replies

5. UNIX for Dummies Questions & Answers

hwo to find shared filesystem and local filesystem in AIX

Hi, I wanted to find out that in my database server which filesystems are shared storage and which filesystems are local. Like when I use df -k, it shows "filesystem" and "mounted on" but I want to know which one is shared and which one is local. Please tell me the commands which I can run... (2 Replies)
Discussion started by: kamranjalal
2 Replies

6. AIX

how to find out disk capacity

Hi, I would like to know how to find out disk capacity if it is assigned from the storage as a lun. as per below command , I am unable to find out disk capacity. $ bash bash-3.00$ lspv hdisk1 0001579a7fa3c086 None $ lscfg -vl hdisk1 hdisk1 ... (8 Replies)
Discussion started by: manoj.solaris
8 Replies

7. Shell Programming and Scripting

Filesystem alert shell script not working!!

Hi All, My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert: #!/bin/bash export DBALIST="abc@xyz.com" df -k /oradata/xyz/archive > dfk.result archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4` if ] then... (5 Replies)
Discussion started by: a1_win
5 Replies

8. UNIX for Dummies Questions & Answers

How to find filesystems crossed 90% capacity

Hi experts, How do i find which are the filesystems which has crossed 90% capacity in solaris box. thanks Shaan:) (4 Replies)
Discussion started by: shaan_dmp
4 Replies

9. Shell Programming and Scripting

shell script to mount filesystem

Hi, Gurus: I need your help to finish a script that will mount two file systems automatically when saver is reboot or start. I am working on a new Sun Sparc machine with Solaris 9 on it. This box got two disk. disk one has been partitioned to hold Solaris OS. disk two has been partitioned as... (6 Replies)
Discussion started by: duke0001
6 Replies

10. Filesystems, Disks and Memory

how to find memory capacity.

Hi, In Sun solaris o/s how can i find the memory space available,Swap space. By giving df command i can get the disc space. I want RAM space & swap space. If anybody assist me.that is great. Thanks (2 Replies)
Discussion started by: Mar1006
2 Replies
Login or Register to Ask a Question