|
|
# 8 | |
|
I am root
|
ציטוט:
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 ? או להמשיך מונה עולה .. אם זה מונה עולה , אז תשתמש ברעיון שלי ותתפרע איתו, בהתחלה בניתי את זה כמונה טיפש שכזה.... |
|
|
| חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים) | |
| כלים לאשכול | |
| תצורת הצגה | |
|
|