View Single Post
ישן 13-04-09, 10:14   # 8
yonatan
I am root
 
yonatan's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: אשדוד
גיל: 39
הודעות: 3,911

yonatan לא מחובר  

Cool

ציטוט:
נכתב במקור על ידי nin770 צפה בהודעה
ב"ה

שלום חברים!

אני מחפש מונה שיספור מספר ויעלה אותו רק משעה 18 בערב ולא מ00 בלילה

אני ממש מודה לכם!
שירבטתי קצת , נראה לי שזה עובד.

http://www.isra3l.net/bash/counter0.1.sh.gz

קוד:
#!/bin/bash
#
# Script Name : Counter
# Script Purpose : to count what is the time from 18pm and report to a file called " time.txt " the current time.
# Author : Yonatan Pingle
# Real Purpose : waste time while playing with bash
# if you can make it better please feel free to send your ideas to :  yonatan "AT" securehost.co.il
#
# Note: i know its ugly usage of inodes - but it was quicky, so only if u want to make it less filesystem intensive be my guest!
#

        #when to start
        [ `date +%H` -eq "18" ]

# should we start?
if [ $? == '0' ] ; then

# lets count! from 18pm and over ....
while true

        do
                # avoid too much cpu usage
                sleep 1800

        # count the first hours since we started
        for i in `echo {17..23}` ; do echo `expr $i + 1` >$i.txt ; [ `date +%H` -eq `cat $i.txt` ] && expr $i + 1 >time.txt ; done

        # count the rest of the days from now on ....
        for i in `echo {0..8}` ; do echo `expr $i + 1` >$i.txt  ; [ `date +%H | sed -e 's/0//g'` -eq `cat $i.txt` ] && expr $i + 1 >time.txt ; done
        for i in `echo {9..16}` ; do echo `expr $i + 1` >$i.txt ; [ `date +%H` -eq `cat $i.txt` ] && expr $i + 1 >time.txt ; done

# the loop ends.
done

# we should not start!
        else

# if something is very wrong you would see this exit status.
# look at the clock! its not six yet!
exit 3

fi
תכין לזה תיקיה משלו כי זה מלכלך אחריו .. חחח זה הקונספט וזה עובד, משם תמשיך הלאה הכל יהיה סבבה

בעקרון הקובץ שמעניין אותך נקרא time.txt
הוא אומר מה השעה הנוכחית.

מה שלא הבנתי כלכך, אחרי שמגיע חצות , אתה רוצה לספור שוב מ 0 ? או להמשיך מונה עולה ..
אם זה מונה עולה , אז תשתמש ברעיון שלי ותתפרע איתו, בהתחלה בניתי את זה כמונה טיפש שכזה....
__________________
אחסון אתרים - Red Hat Certified
עקבו אחרינו בטוויטר!

  Reply With Quote