Sometimes my until loop misses it's target


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sometimes my until loop misses it's target
# 1  
Old 06-02-2009
Sometimes my until loop misses it's target

Hello all,

I wrote a quick function (alarm) in my bash_profile (in cygwin) for practice. It uses until loops to wait for a specified time, and once that time passes triggers a play on a mp3. Most of the time it works, however sometimes it seems like it's looping through too slowly and will miss the trigger time. Once this happens it just keeps going, and never ends...well I suppose it will end, just 24 hours later than it's supposed to.

Code:
alarm () #A simple alarm program that I wrote
{
if [ -z "$1" ];then #if no time is specified, exit with a warning
printf "You must specify a time to use this function"
return
fi
if [ -z "$2" ];then #if no alarm music is specified, then just count down to alarm time
alarm="Alarm set for $1"
date=$(date '+%H%M%S')
until [ "$date" = "$1" ];do
printf "$alarm\nNope, it's not time yet, it's only $date"
#sleep 1
date=$(date '+%H%M%S')
clear
done
elif
[ -n "$2" ];then #Check to see if alarm music is specified
        if [ ! -f "$2" ];then #make certain that the alarm music is a real file, if it is, play that file, if not play default alarm 
        echo "Uh-oh, it looks like the file you've chosen doesn't exist, so I'm just going to play Strangers by The Kinks"
        alarm="Alarm set. At $1 Strangers by The Kinks will be played"
        date=$(date '+%H%M%S')
        until [ "$date" = "$1" ];do
        printf "$alarm\nNope, it's not time yet, it's only $date"
#       sleep 1
        date=$(date '+%H%M%S')
        clear
        done
        cygstart /home/D/strangers.mp3 &
        else
        alarm="Alarm set. At $1 $2 will be played"
        date=$(date '+%H%M%S')
        until [ "$date" = "$1" ];do
        printf "$alarm\nNope, it's not time yet, it's only $date"
        #sleep 1
        date=$(date '+%H%M%S')
        clear
        done
        cygstart "$2" &
fi
fi
}

At first I thought the sleep in the middle of the loop was the issue, but I commented that out, and it still happens.

As always I welcome any suggestions on how to fix this issue, or any critique on how I could have accomplished this same goal differently/more effectively.
# 2  
Old 06-02-2009
You should change the = for the date check against $1 to make is >= so that it will execute when it hits the time for is is just past that time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command finds some, misses some

The contents of my home directory: bin Desktop Documents Downloads folders Music Pictures Public Templates Videos When I run the command for file in /home/myself/*d*; do if ; then echo $file; fi; doneit finds /home/myself/Downloads /home/myself/Videos but not "folders". ... (5 Replies)
Discussion started by: Xubuntu56
5 Replies

2. UNIX for Dummies Questions & Answers

Remove symlink and target

i would like to remove a directory and also symlink target inside. my_directory -- file1 -> /targetpath/file1 -- file2 -> /targetpath/file2 rm -rf my_directory will not remove symlink target. rm -rf "`readlink -f file1`" will only remove target if specifying the symlink is specified ... (4 Replies)
Discussion started by: lsy
4 Replies

3. HP-UX

After adding new iscsi target port, still the session state of that target port is showing offline

Hi, I wanted to configure new iscsi port on HPUX system, i added the target port address and configured it, once done, went to array side and searched for that host iqn number , but was nt able to find the same, came to host, then when i ran "iscsiutil -pVS" command it gave me below result ... (0 Replies)
Discussion started by: Vinay Kumar D
0 Replies

4. HP-UX

swinstall not working with target

Hi, I have installed a software using the command(swinstall -s /Softwares/Game.pkg AngryDog.nwr-cbin @/z_temp). During installation I didn't find any error, also I can find a folder structure(opt/angrydog...) getting created under "/z_temp" and all files are present. But software is not working.... (1 Reply)
Discussion started by: Thunderbird288
1 Replies

5. Shell Programming and Scripting

MakeFile Backup Target

Goal: I'm trying to create a PHONY target inside my Makefile so that when I run the command "make backup", It will move all the files that end in "~" into the specified backup folder. Here is my code currently, and I'll explain the problem after: .PHONY: backup backup: @mkdir -p... (2 Replies)
Discussion started by: Xploit
2 Replies

6. Programming

Cross target debugging

I am trying to setup gdbserver debugging on my i386 target platform and running gdb from x86_64 host. I always get could not load vsyscal try using file etc.. error. Is there a clean way to setup a cross target gdb. PS: I also tried set archi i386 on host side. (2 Replies)
Discussion started by: dragonpoint
2 Replies

7. Shell Programming and Scripting

loop directories mv files to target in range

Hello, Currently I have a painstaking process that I use to move file for a monthly archive. I have to run the same two commands for 24 different directories. I wish to have a script with a for loop automate this and I have not been able to succeed. Here is what I do 24 times. I know this is... (5 Replies)
Discussion started by: jaysunn
5 Replies

8. UNIX for Advanced & Expert Users

VxWorks target server

hi all. i have omniswitch 6800 that runs vxworks 5.4.x The folder that is result of compiling my image consists of : -rw-r--r-- 1 root other 8128249 Jun 21 05:21 Kbase.img -rw-r--r-- 1 root other 971810 Jun 21 06:07 Kos.img -rw-r--r-- 1 root other 295076 Jun 21... (0 Replies)
Discussion started by: sadgb
0 Replies

9. Shell Programming and Scripting

Read from text file misses first line

Hi! I need to read in the first line from a text file (which will only ever have one line in it), so I tried this.... while read line do echo $line done < $file But this wasn't returning anything. So I tired a different file, which had multiple lines of text in it, and it returned... (2 Replies)
Discussion started by: davewg
2 Replies

10. UNIX for Dummies Questions & Answers

vi, c/source/target g?

hi in vi, i have a file and i wanted to replace all wnix to unix. is the below correct. c/wnix/unix g... i have tried , and the above is not right... help? (7 Replies)
Discussion started by: yls177
7 Replies
Login or Register to Ask a Question