LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 01: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, 01: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, 07: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, 08: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 08:38 AM.
 
  


Reply



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 01:22 PM
I can't do an incrimental backup anymore with an XP box. trilect Linux - Networking 2 08-20-2004 08:30 AM
Counter-strike,[color=orange]H ë L F - L I F E ²[/color],Counter-strike: Source. Dennisgoop Linux - Games 2 08-10-2004 03:03 AM
Counter-strike help please effect Linux - Games 2 07-02-2004 05:16 PM
Counter AMMullan Programming 5 10-23-2003 02:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:13 AM.

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