Sponsored Content
Top Forums Shell Programming and Scripting Please help to debug a small shell script (maybe AWK problem)? Post 302247266 by GreatJerry on Wednesday 15th of October 2008 09:48:00 AM
Old 10-15-2008
Please help to debug a small shell script (maybe AWK problem)?

Hi Buddies,
The following is shell scripts which was borrowed from linux box for load average check. it runs good.
(this structure is simple, when load average is too high, it will send alert to user)


#!/usr/bin/ksh

# Set threshold for 1, 5 and 15 minture load avarage
# configured for 12-processors system

max_1=48
max_5=36
max_15=24

# Set the string which appears before the load average in the uptime command
load_text='load average: '

#Email list
mail_to='abc@abc.com'

alert=n

up=`uptime`

# Parse out the current load average from the uptime command

load_1=`echo $up | /usr/xpg4/bin/awk -F "$load_text" '{ print $2 }' | cut -d, -f1 | cut -d. -f1`

load_5=`echo $up | /usr/xpg4/bin/awk -F "$load_text" '{ print $2 }' | cut -d, -f2 | cut -d. -f1`

load_15=`echo $up | /usr/xpg4/bin/awk -F "$load_text" '{ print $2 }' | cut -d, -f3 | cut -d. -f1`

# Set alert=y if any of the average are above their thresholds
if [ $load_1 -ge $max_1 ]
then
alert=y
elif [ $load_5 -ge $max_5 ]
then
alert=y
elif [ $load_15 -ge $max_15 ]
then
alert=y
fi

# Send mail if the alert threshold was reached
if [ ! $alert = n ]
then
mail -s "High load on procede02" $mail_to < `uptime`
fi

---
Now we use it in solaris 9, get some errors like

$./monitor_load_average.sh
./monitor_load_average.sh[43]: 9:32am up 3 day(s), 6:30, 9 users, load average: 0.32, 0.58, 0.55: cannot open


Can any expert give me a hand to debug it? (why have [43]..? why can not open? ..I think this is a syntax problem in AWK..)


Thank you very much in advance

Jerry
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Debug an Awk Script

I would like to extract the following fields from the text file attached. I copied the contents from a pdf file and pasted them into the text file so I can use awk to extract them. The layout is as listed below. name1,name2,name3,name4,Title,designation,nationality,dob, national ... (1 Reply)
Discussion started by: mboro
1 Replies

2. Shell Programming and Scripting

How to debug the awk script

Hi, How can I debug an awk script? I know that set -x can be used to debug a script. But this will not suite for awk scripts. Can anyone help me? Thanks in advance, Chella (2 Replies)
Discussion started by: chella
2 Replies

3. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

4. Shell Programming and Scripting

Very small Shell Script Help...

The following Script takes each extension and determine what category it belongs and then moves it into a directory based on the extension. (for eg. 1.sh, 5.sh, 9.sh together; 4.csh, 120.csh, 6.csh together and 7.ksh, 2.ksh, 59.ksh together) and moves them to their respective directories viz.... (2 Replies)
Discussion started by: marconi
2 Replies

5. UNIX for Advanced & Expert Users

How can debug our UNIX shell script?

Hi all, i have two simple questions here... 1. i want to know that how to debug the UNIX shell script? 2. is there any way to handling the exception in UNIX shell script like oracle exception handling? Please provide me those details it would be great help/ Thanks and Regards, MPS... (3 Replies)
Discussion started by: psiva_arul
3 Replies

6. Shell Programming and Scripting

anyone!! debug this small script..thanks in advance..

x="PermitRootLogin no" cd /etc/ssh y=`cat sshd_config |grep "PermitRootLogin"` if ] then print "Sorry, Remote Root SSH login already disabled." exit else print "Welcome to Remote SSH Login disable script." fi output: + x=PermitRootLogin no + cd /etc/ssh + + cat sshd_config... (2 Replies)
Discussion started by: solaix14
2 Replies

7. UNIX for Dummies Questions & Answers

A small AWK problem

I have a file tmp.out with contents: 2008-08-09 05:11:01 2008-08-09 08:52:59 2008-08-11 12:08:34 2008-08-11 12:15:40 I want the output to be: 3|0|1|71|2008-08-09 05:11:01|2008-08-30 11:19:28 4|0|1|71|2008-08-09 08:52:59|2008-08-30 11:19:28 5|0|1|71|2008-08-11 12:08:34|2008-08-30 11:19:28... (6 Replies)
Discussion started by: ChicagoBlues
6 Replies

8. Shell Programming and Scripting

Problem with the script, help me debug

Hi, When i run the script ./script.sh sun, this give me no output, it should give me the list of file. If i run the script without the argument it should send me echo inside usage(). What is the problem? please help -Adsi #!/bin/sh ROOT_PATH=/net/icebox/vol/local_images/spins... (2 Replies)
Discussion started by: asirohi
2 Replies

9. Shell Programming and Scripting

Cant debug shell script

Hi I am relatively new in shell scripting Below is the code which i developed but for some reason, it keeps giving me error: /apps/bss/BatchProg/at1/batch/scripts/ksh/TBATLC02.ksh: syntax error at line 41 : `then' unmatched #!/usr/bin/ksh... (4 Replies)
Discussion started by: scripting_newbe
4 Replies

10. Shell Programming and Scripting

[Solved] How to debug awk script?

how can i view what variables are stored upon the excution of an awk script. something equivalent to shell eg. sh -vx "script_file" many thanks in advance! (1 Reply)
Discussion started by: Apollo
1 Replies
UPTIME(1)							Linux User's Manual							 UPTIME(1)

NAME
uptime - Tell how long the system has been running. SYNOPSIS
uptime uptime [-V] DESCRIPTION
uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. This is the same information contained in the header line displayed by w(1). System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time. FILES
/var/run/utmp information about who is currently logged on /proc process information AUTHORS
uptime was written by Larry Greenfield <greenfie@gauss.rutgers.edu> and Michael K. Johnson <johnsonm@sunsite.unc.edu>. Please send bug reports to <albert@users.sf.net> SEE ALSO
ps(1), top(1), utmp(5), w(1) Cohesive Systems 26 Jan 1993 UPTIME(1)
All times are GMT -4. The time now is 01:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy