Limiting the Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Limiting the Script
# 8  
Old 12-06-2012
Issue is that it Compares the Hours each time when the script runs
for eg., at 2:00 PM the script runs first it will store the 2012120702
and when script runs 2nd time again 2012120702 so the script will
generate the email because last hours also 2 and this time also 2

Below is the script which i tested

Code:
#!/bin/bash
set -xv
#Current Time Stamp
CURR_TS=$( date +"%Y%m%d%H" )
FILE_TS=$( cat /tmp/curr_ts.txt 2> /dev/null ) # Time stamp in file
#admin email account
ADMIN=abc@test.com
# set usage alert threshold
THRESHOLD=60
#hostname
HOSTNAME=$(hostname)
#mail client
MAIL=/bin/mail
# store all disk info here
EMAIL=""
for line in $(df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }')
do
        part=$(echo "$line" | awk -F"_:_" '{ print $1 }')
        part_usage=$(echo "$line" | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 )
        if [ $part_usage -ge $THRESHOLD -a -z "$EMAIL" ];
        then
                EMAIL="$(date): Running out of diskspace on $HOSTNAME\n"
                EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"
        elif [ $part_usage -ge $THRESHOLD ];
        then
                EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"
        fi
done
if [ -n "$EMAIL" ] && [ "$CURR_TS" -eq "$FILE_TS" ];
then
        echo -e "$EMAIL" | $MAIL -s "Alert: Partition(s) almost out of diskspace on $HOSTNAME" "$ADMIN"
 else
       echo $CURR_TS > /tmp/curr_ts.txt;
fi


Last edited by manju98458; 12-06-2012 at 11:11 PM..
# 9  
Old 12-06-2012
I said to send email only if the CURR_TS and FILE_TS is not matching, so perform the below correction and re-try:-
Code:
if [ -n "$EMAIL" ] && [ "$CURR_TS" -ne "$FILE_TS" ];

# 10  
Old 12-06-2012
No luck still the mails are going when i run the script 2nd and 3rd time alsoSmilie
# 11  
Old 12-06-2012
I have 2 questions for you

1. Why do you have 2 shebangs in your script!
Code:
#!/bin/bash
set -xv
#!/bin/sh

2. Why you are not using absolute path for curr_ts.txt file here?
Code:
echo $CURR_TS > curr_ts.txt; # replace it with /tmp/curr_ts.txt

# 12  
Old 12-06-2012
Step 1. I accidently put that i removed it.
Step 2. Sorry, I have included the path.

Now, Once again I run the script twice still the same issue
# 13  
Old 12-06-2012
OK.
Set the debug and see what is going on.
Echo the values of $CURR_TS and $FILE_TS right before the final if condition.
Check the values and check the if condition execution flow.
# 14  
Old 12-07-2012
You havent answered my first question yet : why 17 and not 15 minutes? This question is fundamental since you re wanting an hourly mail
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Limiting access to postqueue

Hi, I have a Debian 6 machine running Postfix 2.7.1. The email server works pretty well. I discovered that any non-root user can access to the mail queue using postqueue command just like root. How can I limit this access? (1 Reply)
Discussion started by: mjdousti
1 Replies

2. Solaris

Limiting Connections from a single IP

I'm looking for a way to limit connections to a Solaris 10 box from any single IP. The problem is that I've had more experience doing this with IPTables on Linux, rather than with IPFilter, which I've found to be somewhat feature-poor. I hope there is some way to do this using IPFilter, I've... (2 Replies)
Discussion started by: spynappels
2 Replies

3. Emergency UNIX and Linux Support

Limiting a user to a script upon login, nothing else.

Hi there, I have a Debian 5.0 server that my company uses for deployment testing. This server needs to be accessed by NOC people that have no NIX knowledge whatsoever. I am creating a bash script for a menu-based command interface for the commands they need to run on their testing routines,... (21 Replies)
Discussion started by: ppucci
21 Replies

4. HP-UX

Limiting SFTP Users While Not Limiting Regular Users?

Hi, I have searched the web and have come back with nothing that is satisfactory for what I require. SFTP is my corporations new file transfer standard. What I require is a method to lock down SFTP users to their directory (they may go to sub directories) while not restricting regular users. ... (2 Replies)
Discussion started by: Emancipator
2 Replies

5. UNIX for Dummies Questions & Answers

SSH keys and command limiting ...

Hi, I've just been trying to setup so that server1 can ssh into server2 and execute a limited set of commands only without password login. I want it also to be able to login with a password if no command given at all though (bit I'm stuck on). I have got this almost working with authorized_keys... (1 Reply)
Discussion started by: moomain
1 Replies

6. HP-UX

limiting failed logins to three

I have tried limiting failed logins to three by the following method logins -ox \ | awk -F: '($8 != "LK" && $1 != "root") { print $1 }' \ | while read logname; do /usr/lbin/modprpw -m umaxlntr=3 "$logname" done /usr/lbin/modprdef -m umaxlntr=3 but it is failing on the 4th... any ideas?... (1 Reply)
Discussion started by: csaunders
1 Replies

7. UNIX for Dummies Questions & Answers

question about limiting the display from the ls command

hey guys im rly new to unix. im attempting to list the 5 largest files in a directory. so i got this far... ls -lR | sort -r and this lists all files by filesize, how can i limit this to only the 5 largest? (4 Replies)
Discussion started by: Aesop
4 Replies

8. UNIX for Advanced & Expert Users

Limiting telnet sessions on HP UX Box

Anyone know how to limit the telnet sessions on a per user basis on an HP UX Box. I would like to limit the Maximum number of telnet seesions a user can open at any give time to around 4 or 5. I have been looking and looking and do not seem to be able to find anything on this. Any help would be... (2 Replies)
Discussion started by: Witlr
2 Replies

9. UNIX for Dummies Questions & Answers

Limiting access

Hi, I'm new to linux and unix, and i have couple of problems: 1) how can i limit the access for a user, for example, i created a user, and i want that this user will be able to be only in one directory, and will see only the files i want him to. 2) I have a domain name, and i want that every... (4 Replies)
Discussion started by: misha
4 Replies
Login or Register to Ask a Question