Time check!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Time check!
# 1  
Old 05-28-2010
Time check!

How can i do something, that will be doing periodicaly for 24 hours
and then do something else.
For example:

i want to write "time" in a text file every 10 sec
but only for the next 24 h and then rewrite all that data to an other file,
then again write "time" in the first file every 10 sec, but it must not contain
any of the old "time" just the new data Smilie and repeat that over and over...

while true; do

sleep 10
echo -e " +%T" >> present.txt

after 24 h do...
present.txt >> old.txt and delete all data in the present.txt, so it
can store new data
# 2  
Old 05-28-2010
Code:
#!/bin/sh

time=0;

while true; do

until [ $time = 86400 ]; do
date "+%T" >> present.txt
time=$(($time+10))
sleep 10
done

time=0
cp present.txt present.old
>present.txt
done

These 2 Users Gave Thanks to pseudocoder For This Post:
# 3  
Old 05-28-2010
pseudocoder's answer is correct conceptually and basically a good idea. However unix does not play fair. sleep 10 guarantees a minimum of 10 seconds, it could and sometimes is more.

At the end of the day you could have slipped by any number of seconds and therefore miss the intedned "until" limit in the code completely

Pete|1 - what are you trying to accomplish?

Last edited by jim mcnamara; 05-28-2010 at 05:25 PM.. Reason: cannot type
# 4  
Old 05-28-2010
# 5  
Old 05-28-2010
You are pushing the limits on the rules here.

There are two ways,one using C and the wptmp[x] file, the other with who
using what pseudocoder gave you
Code:
t=0
while [ t -le 86400 ]; do
  echo " `date +%T`  Users: `who | wc -l`"
  t=$((  $t + 1 ))
done > list.txt

The forums here are really NOT for homework; they are for unix users with problems.
We have a forum for homework. Posting homework outside the homework forum is not supposed to happen. Please do not do it again.

As you can see a partial answer is simple. You get to do some work to extend it to a 'forever solution'. Your prof wanted you to use 3 commands - date and who and wc.
This User Gave Thanks to jim mcnamara For This Post:
# 6  
Old 05-28-2010
Thanks for everything Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if time format is valid

How can I validate if time (HH:MM:SS) argument is valid? I got this from web but I can't modify it to exit the script if the time argument is invalid. echo $1 | awk -F ':' '{ print ($1 <= 23 && $2 <= 59 && $3 <= 59) ? "good" : "bad" }' ex: ./script.ksh 12:34:21 = okay ./script.ksh... (10 Replies)
Discussion started by: erin00
10 Replies

2. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

3. Shell Programming and Scripting

how to check whether a process started at particular time

I want to check whether a particular process has started at 10:00a.m or not. I can check process by ps -fu but dont know how to check it with respect to time. Could anyone help me with this? ---------- Post updated at 11:14 AM ---------- Previous update was at 10:52 AM ---------- can i use... (9 Replies)
Discussion started by: kishore kumar
9 Replies

4. Shell Programming and Scripting

Check file time stamp

Hi, I need help to read file in a directory on basis of time stamp. e.g. If file access in last 2 minutes it should not be copy to remote directory. Below is my script. #!/bin/ksh DATE=`date +"%Y-%m-%d_%H%M"` SEPARATER=" " exec < out_interfaces.cfg while read source_path... (10 Replies)
Discussion started by: qamar.alam
10 Replies

5. UNIX for Dummies Questions & Answers

check if two files exists at the same time in one location

Hi friends, I am trying to check if the two files i am expecting are created in a specific location. if both files does not exist, do an echo if -a ]; then echo "files not found" fi It gives me the following message: bash: Please help! :) (3 Replies)
Discussion started by: kokoro
3 Replies

6. UNIX for Dummies Questions & Answers

Check time and Increase counter

Hi all... the last two weeks have been very educational... I went through a bunch of websites about linux and its commands.. still not have mastered it nor its many operators ... and symbols. I wish I had more time to dig to the next and unix.com but I m on a deadline for this project. I... (2 Replies)
Discussion started by: abilash.amara
2 Replies

7. Shell Programming and Scripting

Check data and time

I am attempting to figure out how to do a time check within my script. For some reason I can not seem to get this to work correctly. I want the script to first see if it is Saturday. If it is Saturday then check to see if it's between the time 5:30am and 6:30am. If it is between 5:30am and... (4 Replies)
Discussion started by: LRoberts
4 Replies

8. Shell Programming and Scripting

Check Time/Date on a server

I have two servers which are not in sync. I need to write a script that checks the time on the corresponding server and another script to call the above script on both the servers simulataneously to check if there is a time difference. Can anyone provide me with such scripts as I am new to... (3 Replies)
Discussion started by: ravneet123
3 Replies

9. Solaris

How to check CPU spike between certain priod of time

Hi, Does anyone know how to check which process has been used the most CPU between certain time period? say I have noticed CPU spike happend between 1:00 to 1:30 now it is 3:00 o'clock already. Is there anyway to find out what process/PID use the most CPU then? Thanks a lot (3 Replies)
Discussion started by: uuontario
3 Replies
Login or Register to Ask a Question