LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-23-2007, 07:08 AM   #1
kristam269
LQ Newbie
 
Registered: Jan 2007
Posts: 1

Rep: Reputation: 0
need some help regarding command line arguments


Hi,

For Now I have to pass 5 command line arguments.

sh test.sh 0 tomcat bin /app/tomcat /app/tomcat/bin/logs

I need to implement the disk usage part in a loop instead of writing multiple times that part.

diskusage_value1=`du -k $4 | tail -1 | awk '{ print $1}'`
echo $diskusage_value1
if [ $diskusage_value1 -ge $THRESHOLD_VALUE ]; then
echo "Reached the Threshold limit for \"$4 ($diskusage_value1%)\" on `hostname` as on `date`" |
mailx -s "Alert: Almost out of diskspace for $4" $MAILER_LIST
fi

diskusage_value2=`du -k $5 | tail -1 | awk '{ print $1}'`
if [ $diskusage_value2 -ge $THRESHOLD_VALUE ]; then
echo "Reached the Threshold limit for \"$5 ($diskusage_value2%)\" on `hostname` as on `date`" |
mailx -s "Alert: Almost out of diskspace for $5" $MAILER_LIST
fi

This part should be in loop instead of writing two times.

for that I tried this one not able to get the results.

i=4
n=`expr $# + 1`
a='$'

while test $i != $n
do
b=${a}$i
echo $b
diskusage_value1=`du -k $b | tail -1 | awk '{ print $1}'`
echo $diskusage_value1
if [ $diskusage_value1 -ge $THRESHOLD_VALUE ]; then
echo "Reached the Threshold limit for \"$4 ($diskusage_value1%)\" on `hostname` as on `date`" |
mailx -s "Alert: Almost out of diskspace for $4" $MAILER_LIST
fi
i=`expr $i + 1`
done
-----------------

diskusage_value1=`du -k $b | tail -1 | awk '{ print $1}'`

here $b becomes $4 not becoming $4value(/app/tomcat).
I think problem with this line b=${a}$i.
Please let me know how to solve this one.

Thanks,
 
Old 01-23-2007, 09:40 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It seems you should try using the bash builtin variable '$#', which contains the number of arguments. This can be used as your loop counter, which is what it appears you are trying to achieve. Also, you probably want to apply the shift operator, to shift each argument into '$1'. This snippet (untested) should demonstrate.
Code:
#! /bin/sh

echo $#;
i=0
j=$#

while [ $i -lt $j ] ; do
echo $i $1
shift
i=`expr $i + 1`;
done
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
command line arguments nickraj Programming 6 09-11-2006 01:01 PM
Command line arguments?? almagerenia Linux - Newbie 1 09-08-2006 04:05 AM
command line arguments containing ( Lotharster Linux - Newbie 3 01-05-2006 08:43 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 09:09 PM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 02:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration