LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2010, 02:34 AM   #1
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Rep: Reputation: 0
Question incrimental counter


hi all
(newboy)
i am just starting a ubuntu server and i am trying to learn
i have a script that runs ever hour and i would like to put a counter
(count=count+)
in a line if it is true
and also if the counter reaches its value of 10 to reset the counter to zero
thanks
joe
 
Old 06-23-2010, 02:51 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
This way perhaps:
Code:
count=0

while sleep 1h; do
    # < run something here >

    (( count = (count + 1) % 10 ))
done
Why reset the counter to 0 by the way?
 
Old 06-23-2010, 08:58 AM   #3
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
Thumbs up

hi thanks for the swift reply
the reason for the count to go to zero is because after 10 counter i restart the pc so i let the script do its part

i have a crontab that run a script ever 2 hours which checks somthing and if it fail the test ten time i do a restart


what does this line mean?(in english ha ha )
while sleep 1h; do
 
Old 06-23-2010, 09:31 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by joesto View Post
what does this line mean?(in english ha ha )
while sleep 1h; do
Here the while compound command will execute/call sleep with the paramater "1h" for every loop. If you look at 'sleep --help', 1h should imply 1 hour. So the sleep command will be running or sleeping itself for 1 hour then when it's done passes the control back to while. If you press ctrl-c while "sleep" is running, a false exit code will return (probably 127 or -127) which will tell 'while' to end the loop.

Helpful commands:
Code:
help while
sleep --help
man sleep
man bash

Last edited by konsolebox; 06-23-2010 at 09:38 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
while counter B-Boy Programming 14 08-13-2008 02:22 PM
I can't do an incrimental backup anymore with an XP box. trilect Linux - Networking 2 08-20-2004 09:30 AM
Counter-strike,[color=orange]H L F - L I F E [/color],Counter-strike: Source. Dennisgoop Linux - Games 2 08-10-2004 04:03 AM
Counter-strike help please effect Linux - Games 2 07-02-2004 06:16 PM
Counter AMMullan Programming 5 10-23-2003 03:11 PM


All times are GMT -5. The time now is 04:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration