The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accumulate counter in script Pablo_beezo Shell Programming and Scripting 2 05-06-2008 08:43 AM
counter problem jwholey Shell Programming and Scripting 2 03-19-2008 04:39 PM
Error in Script (counter) Felix2511 UNIX for Dummies Questions & Answers 2 12-13-2007 07:30 AM
counter in a variable - can it be done? gazz1982 Shell Programming and Scripting 3 08-09-2007 10:47 PM
Increment counter in ksh steiner Shell Programming and Scripting 5 12-02-2003 08:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2008
Sunguy222 Sunguy222 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Counter Script..help please

I have generated a script that will email a list of people if a certain PID is not running, using "mailx". I have the script running every 5 minutes as a cron job.

I want the script to stop sending an email, if the email has been sent 5 times (meaning PID is dead). I want this so that my inbox doesn't get full.

Do I implement a "for loop" or "counter" syntax in my script? If so, can someone help with the code.

Thanks. Cheers!
  #2 (permalink)  
Old 02-25-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
You can keep the count in a file whenever you send mail.
  #3 (permalink)  
Old 02-25-2008
Sunguy222 Sunguy222 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Thanks for the response. How would I implement this in a file
  #4 (permalink)  
Old 02-25-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool counter file

What you are doing is storing the counter number in a file call my_cntr. Every time the file is run, the counter is increased by one. This will handle your counter issue. You then just need to mix your other requirements in with this code section.
There are two echo's to the screen that you can remove; they are not essential to the program execution. They are the "#print to screen" lines.


Code:
#! /bin/bash
# to read a counter

if [ -s my_cntr ]
# counter file exists
   then
      last_val=$(cat my_cntr)
      echo "current: "$last_val  #print to screen
      next_val=$(($last_val + 1))
      echo "next: "$next_val   #print to screen
      echo "$next_val" >my_cntr
   else
      echo "1" >my_cntr
fi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0