While loop in certain interval


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop in certain interval
# 8  
Old 10-15-2013
try something like this

Code:
$ now=$(date +%s)
$ a_6am_cross=$(date -d" 6:00:01 AM" +%s)
$ if [ $now -eq $a_6am_cross ]; then echo "Its 6:00:01 exiting your exit code goes here"; else echo "Keep looping";fi


Last edited by Akshay Hegde; 10-15-2013 at 02:10 PM..
This User Gave Thanks to Akshay Hegde For This Post:
# 9  
Old 10-15-2013
Quote:
Originally Posted by Akshay Hegde
try something like this

Code:
$ now=$(date +%s)
$ a_6am_cross=$(date -d" 6:00:01 AM" +%s)
$ if [ $now -eq $a_6am_cross ]; then echo "Its 6:00:01 exiting your exit code goes here"; else echo "Keep looping";fi

Thanks,

when implement this code, I got below error:
$ a_6am_cross=$(date -d" 6:00:01 AM" +%s)
Code:
date: illegal option -- d
date: illegal option --
date: illegal option -- 6
date: illegal option -- :
date: illegal option -- 0
date: illegal option -- 0
date: illegal option -- :
date: illegal option -- 0
date: illegal option -- 1
date: illegal option --
date: illegal option -- A
date: illegal option -- M

Would you please take a look.

Thanks
# 10  
Old 10-15-2013
Its working on my pc...which OS ?

Code:
a_6am_cross=$(date -d " 6:00:01 AM" +%s)

try simply these commands on terminal first

$ date -d " 6:00:01 AM" +%s
$ date +%s
This User Gave Thanks to Akshay Hegde For This Post:
# 11  
Old 10-15-2013
I assume the error lies in communication Smilie

Dont have to copy paste the leading $ (or # in other examples).
$ indicates you write the command as user.
# indicates you write the command as root.

That comes from the indicator of PS1 PS1="\\$"
Which shows either $ or # depending on user ID (eg: 0 vs 500/1000).

Hope this helps

EDIT: Err, just tried myself, doesnt seem to be the reason - sorry.
Might be of shopt setting maybe?
Works well on 3.11.3-201.fc19.x86_64.
This User Gave Thanks to sea For This Post:
# 12  
Old 10-15-2013
Quote:
Originally Posted by Akshay Hegde
Its working on my pc...which OS ?

Code:
a_6am_cross=$(date -d " 6:00:01 AM" +%s)

try simply these commands on terminal first

$ date -d " 6:00:01 AM" +%s
$ date +%s
when running
Code:
date +%s

I got
Code:
%s

when running
Code:
date -d " 6:00:01 AM" +%s

I got error:
Code:
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

My OS is SunOS Generic_144488-17 sun4v sparc SUNW,SPARC-Enterprise.

Would you please take a look.
# 13  
Old 10-15-2013
Code:
man watch

This User Gave Thanks to ctsgnb For This Post:
# 14  
Old 10-15-2013
Not sure if all prerequisites are met by your system (stat, awk and date commands available and correct version), but this might be worth a shot:
Code:
mkfifo goodfiles     
while [ $(date +%H) -ge 19 -o $(date +%H) -lt 6 ]
  do  awk '{print $2 "\tYES"}' goodfiles & LC_ALL=C stat -c"%G %n" $(cut -d" " -f2 files.txt) 2>&1 1>goodfiles | awk -F\' '{print $2 "\tNO"} END {if (NR>0) exit 20}'; 
      sleep 900
  done

Output of that (yes admittedly, too) long line would be e.g.
Code:
file    YES
file~    YES
file1    YES
file1~    YES
file2    YES
file2~    YES
file3    YES
file3~    YES
file4    YES
file4~    YES
file6    NO
file5    NO

, and exit status 20 should files be missing.

Last edited by RudiC; 10-16-2013 at 03:22 PM..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Repetition in a particular interval

Suppose I have a word which is repeating in a string continuously. I have a set of intervals. Then how do I find the number occurrences of that word in those intervals and their location of occurrences. For example - Suppose there is a huge string anfie.......sirn of 10000 letters. Now the word... (2 Replies)
Discussion started by: ANKIT ROY
2 Replies

2. Shell Programming and Scripting

Interval merging

I do have a file (file1) with a specified interval of 500 counts file1 0 500 500 1000 1000 1500 1500 2000 2000 2500 2500 3000 3000 3500 3500 4000 4000 4500 4500 5000 5000 5500 5500 6000 6000 6500 6500 7000 7000 7500 7500 8000 (3 Replies)
Discussion started by: Kanja
3 Replies

3. Shell Programming and Scripting

interval based count

Hi, I have a file with 4 million rows. what i am trying to achieve is for every 1000 interval count the number of rows and display it i/p 12 200 400 750 1000 1500 1800 2200 2345 2600 2896 3020 3400 (0 Replies)
Discussion started by: Diya123
0 Replies

4. Solaris

NTP polling interval

Is it possible to change the ntp poll manually. I notice that ntp poll is changing autimatically. (1 Reply)
Discussion started by: ningy
1 Replies

5. Shell Programming and Scripting

grep searching interval

Hi all, I just want to find all values that are in a specified interval. I tryed it with grep e- file , it does not work. Is it possible to get values wich are lower a special number, like grep >e-18 file? Thanks a lot (4 Replies)
Discussion started by: newcommer
4 Replies

6. Shell Programming and Scripting

compare the interval of 2 numbers of input2with interval of several numbers of input1

Help plz Does any one have any idea how to compare interval ranges of 2 files. finding 1-4 (1,2,3,4) of input2 in input1 of same key "a" values (5-10, 30-40, 45-60, 80-90, 100-120 ). Obviously 1-4 is not one of the range with in input1 a. so it should give out of range. finding 30-33(31,32,33)... (1 Reply)
Discussion started by: repinementer
1 Replies

7. UNIX for Advanced & Expert Users

Summation of the column value in an interval.

Hey, I have a file with following data.. and I want to get the summation of 10th column. And this happens in every 10 seconds for a minute max. 242001 A mqsitst 794864 1249516 0 60 20 293050400 77016 * 02:05:33 - 0:04 DataFlowEngine EAITIBR2_BROKER... (6 Replies)
Discussion started by: varungupta
6 Replies

8. OS X (Apple)

interval in a launchd script

Hi, i'm planning a to automate my backup with a rsync user deamon in my launchd and let that run every 2 hours. my server contains a lot of video data which can expand rapidly , up to 1TB, in an interval of 2 hours. now i'm wondering what will happen when a rsync is running longer then the... (1 Reply)
Discussion started by: wessel
1 Replies

9. Shell Programming and Scripting

Need Help for interval date

Hello, I need help about a shell script I have a text file with this fields: 2009/01/19 09:33:35: --> ---ORA-28817: PL/SQL function returned an error. 2009/01/19 09:33:35: --> ---ORA-28817: PL/SQL function returned an error. 2009/01/19 09:33:35: --> ---ORA-28817: PL/SQL function returned an... (4 Replies)
Discussion started by: giofai
4 Replies

10. Solaris

Time Wait interval

What is the time_wait interval for Solaris 8/9??? and is it configurable??? For example sometimes a clients pc will freeze up dropping the connection, closing the port. The problem is on our side our system still thinks their logged in (until it realizes it dropped on the otherside and drops on... (1 Reply)
Discussion started by: eloquent99
1 Replies
Login or Register to Ask a Question