wina
wina

Reputation: 55

Unix C-Shell: ?Need help for the this task

i have given a task to make a C-shell script. I have list of ip address and device name respectively. For example;

cal 1 : 100.21.25.10
cal 2 : 100.21.25.11
cal 3 : 100.21.25.12
cal 4 : 100.21.25.14
and so on...

Based on this ip and device name, i need to rsh the ip address and get the disk free of the device. The result of disk free will be save to a log. the details of the log will be have device name need to be housekeep. My idea is:

declared array :

set device =( cal1 cal2 cal3)
set ip = (100.21.25.10 100.21.25.11 100.21.25.12 100.21.25.14)
set highspace = 90

foreach data($ip)
set space = rsh $ip df -k

if (${space} >= ${highspace}) then   
echo "Please Housekeep $device:" >> $device.log
endif

is this gonna work? Or do you guys have better idea? Thanks.

Upvotes: 1

Views: 40

Answers (1)

zwol
zwol

Reputation: 140788

The C shell should never be used anymore. Neither should rsh; we have ssh now.

Your task in Bourne shell:

#! /bin/sh

highspace=90
fs_to_watch=/path/to/filesystem/that/fills/up

exec 0<"$1"
while read cal calno colon addr; do
   space=$(ssh "$addr" df -k "$fs_to_watch" | 
           awk 'NR > 1 { sub(/%$/, "", $5); print $5 }')
   if [ "$space" -gt "$highspace" ]; then
       echo "Please Housekeep Cal-$calno"
   fi
done

Upvotes: 1

Related Questions