Would like to know how to use the IF...THEN...ELSE statements in C shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Would like to know how to use the IF...THEN...ELSE statements in C shell
# 1  
Old 03-13-2009
Would like to know how to use the IF...THEN...ELSE statements in C shell

Hi

I've only been using Unix for a few weeks but am really impressed with its capabilities and ease of use.

I am, however, struggling with a shell script at the moment.

I would like automated reports on Disk Usage and available free space. I've written a straight forward script that will do this for me and I'll be dealing with the crontab later to automate it.

I currently use about 20 different servers and the reports are written to a central location. The properties of these servers vary slightly so that the disk name isn't always the same.

I've tried using multiple greps but it doesn't work as I'd planned. Therefore, I'd like to you an IF THEN ELSE statement.

Here is the current code:

Code:
#!/bin/csh
#
#################################################################
#Script to get disk usage of server                             #
#Creates unique txt file based on server and username           #
#################################################################
#
#
touch `uname -n`_`echo $USER`
rm /xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
touch /xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo Processing...
echo "******************************************************" >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n "DATE:  " >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
date >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n "CURRENT SERVER:   " >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
uname -n >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "CURRENT ORACLE USER: "$USER >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "******************************************************" >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt  
#
#################### Available Disk Space #######################
#
echo "">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "******************* DISK SPACE ***********************" >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
cd /
echo -n " DISK SIZE    ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $2}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n " USED     ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $3}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n " AVAILABLE    ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $4}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n " CAPACITY IN USE   ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $5}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n " MOUNTED ON    ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $6}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo -n " FILE SYSTEM    ">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
df -h | grep '^/dev/dsk/' | grep /dis* | awk '{ print $1}' >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "******************************************************">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
#
#
################### Disk Usage Part #############################
echo "">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "******************* DISK USAGE ***********************" >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "Starting point for " >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
cd ../../../../../
pwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
du -h * | awk '{ print $0}' | grep '[0-9]G'>>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
#
#
#################### User Part ##################################
echo "">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "">>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
echo "******* The Oracle users on this server are **********" >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
grep '^xxx' /etc/passwd >>/xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt
clear
more /xxxxx/disk_usage_output/`uname -n`_`echo $USER`.rpt

I would like to have various versions of the 'Available Disk Space' part so I can be 'server specific'. I'd like to have the script determine the server name (uname -n) and if that equals a certain value (eg SERVER1) then goto the disk space code specific to SERVER1, else, proceed to next command.

I'm not sure how I carry this out - if anyone can help I'd really appreciate it.

Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

2. Programming

Shell script - if statements dont work

hi all, i have made a shell script and it runs until it reaches the if statement, doesn't the ! mean only if the command fails it will echo me that message and then exit can anyone please help me what is wrong with my code? many thanks, rob #!/bin/bash echo "is this archive... (10 Replies)
Discussion started by: robertkwild
10 Replies

3. UNIX for Dummies Questions & Answers

if statements in shell to compare value

Hi, I am a newbie to unix, I am trying to write a shell script (just a test) but I can't seem to compare the variable value with a string in the if statement. I get an error when i execute the following script, could you tell me what is wrong and how I can correct it Note - I am using bash... (4 Replies)
Discussion started by: muthuveerappan
4 Replies

4. Shell Programming and Scripting

Can we use two shebang statements in a single shell script?

Hi, As per my understanding, we can use two shebang statements in a single shell script. Please see below snippet- #!/bin/bash .......## some code A #!/bin/csh .......## some code B exit 0; Here, code A will be executed using bash shell and code B will be executed with c shell. ... (9 Replies)
Discussion started by: tarunmudgal4u
9 Replies

5. Shell Programming and Scripting

Help with IF statements

I am writing a script that does a search for a argument in a file and lists all like occurrences. The script verifies that it is a file and then runs another script that list the lines. My problem is that I need the script to accept a file or a directory and then go to that directory check all... (1 Reply)
Discussion started by: zero3ree
1 Replies

6. Shell Programming and Scripting

If statements....

Good morning all! I want to know if Im interpreting this if statement below right. if(((1) || (0)) && (1)){ do stuff; } This is saying: if true piped into false, then true, then do stuff. Right? What does the && stand for? thanks in advance! ben (3 Replies)
Discussion started by: bigben1220
3 Replies

7. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

8. Shell Programming and Scripting

Please help on IF statements.

I had different problem scenarios with IF statement. Can any expert please enlighten me on the difference with these scenarios. Thank you. 1st Scenario: testdate=`date +%Y%m` test=`cat /var/log/database0.$testdate*.log | grep "Errors found during processing" | tail -10` if then ... (4 Replies)
Discussion started by: filthymonk
4 Replies

9. UNIX for Dummies Questions & Answers

Else in If Statements

Sorry to be a pain, but how does the else work in the if statements? Ive been making scripts with if statements but i cant get the else statements working. Can you help? (8 Replies)
Discussion started by: chapmana
8 Replies

10. Shell Programming and Scripting

Running remote shell script containing sql statements

I have a shell script which resides on three SCO machines containing some simple sqlplus statments. I need to run these scripts remotely. Currently, I am trying to use rsh to do so: rsh hostname myscript args The problem is that the arguments to the sqlplus statements in the remote shell... (4 Replies)
Discussion started by: Madbreaks
4 Replies
Login or Register to Ask a Question