[opensuse] Help with bash script
Ok.. so here's my criteria: if file hasn't been modified in the last minute then while file hasn't been modified in the last minute then sleep for 59 seconds done else copy the file to another directory fi And here is the process: Script runs, launches a perl wrapper asynchronous script. This script will write a file, and I need to wait for that file to be created so I can copy it. This is ran nightly via cron.. The part I am having problems with is the sniffing for that file. So here is what I have: find /tmp/file -mmin -1 >/dev/null if [ $? -eq 0 ]; then while [ find /tmp/file -mmin -1 >/dev/null -eq 0 ]; do sleep 59 done else cp /tmp/file /somewhere fi Or am I way off track, or looking at this the wrong way? The first thing I notice is the if may be redundant. And another thing to note, the script doesn't work as is so I know i'm doing something wrong. -- I say never be complete. I say stop being perfect. I say let's evolve. Let the chips fall where they may. -Fight Club -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 12 February 2009 08:15:17 Ben Kevan wrote:
if file hasn't been modified in the last minute then while file hasn't been modified in the last minute then sleep for 59 seconds done else copy the file to another directory fi
So, you don't want to copy the file after you get done waiting?
Script runs, launches a perl wrapper asynchronous script. This script will write a file, and I need to wait for that file to be created so I can copy it.
Hrm, sounds like you always want to copy the file, not just when you haven't had to wait for it.
This is ran nightly via cron.. The part I am having problems with is the sniffing for that file. So here is what I have:
find /tmp/file -mmin -1 >/dev/null if [ $? -eq 0 ]; then
Can be made a single line.
while [ find /tmp/file -mmin -1 >/dev/null -eq 0 ]; do
-eq doesn't work that way. Just drop the '[' and '-eq 0 ]' and it'll do what you want.
sleep 59 done else cp /tmp/file /somewhere fi
My attempt: while find /tmp/file -mmin -1 >/dev/null; do sleep 59 done cp /tmp/file /somewhere -- Boyd Stephen Smith Jr. ,= ,-_-. =. bss@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/ \_/
On Thu, 12 Feb 2009 07:06:28 -0800, Boyd Stephen Smith Jr.
Hrm, sounds like you always want to copy the file, not just when you haven't had to wait for it.
This is ran nightly via cron.. The part I am having problems with is the sniffing for that file. So here is what I have:
find /tmp/file -mmin -1 >/dev/null if [ $? -eq 0 ]; then
Can be made a single line.
while [ find /tmp/file -mmin -1 >/dev/null -eq 0 ]; do
-eq doesn't work that way. Just drop the '[' and '-eq 0 ]' and it'll do what you want.
sleep 59 done else cp /tmp/file /somewhere fi
My attempt: while find /tmp/file -mmin -1 >/dev/null; do sleep 59 done cp /tmp/file /somewhere
Boyd, Yes, I want to sleep without copying the file, and when the condition was met (file is modified in the last minute) then stop sleeping and send. Here is a little something I just put together, and really thought it would work: FILE=`find /tmp/file -mmin -1` while [ -e $FILE ]; do echo "I feel like sleeping" >/tmp/otherfile exit 1 done echo "Yay look" >/tmp/otherfile But it doesn't continue the condition. I tried what you suggested and it also did about the same thing mine does. What I am looking for is: Keep searching for a certain file, and if it was modified in the last minute then copy it to another location, if it wasn't modified in the last minute, then sleep and check again in 58 seconds. -- I say never be complete. I say stop being perfect. I say let's evolve. Let the chips fall where they may. -Fight Club -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, 12 Feb 2009 09:02:54 -0800, Ben Kevan
On Thu, 12 Feb 2009 07:06:28 -0800, Boyd Stephen Smith Jr.
wrote: Hrm, sounds like you always want to copy the file, not just when you haven't had to wait for it.
This is ran nightly via cron.. The part I am having problems with is the sniffing for that file. So here is what I have:
find /tmp/file -mmin -1 >/dev/null if [ $? -eq 0 ]; then
Can be made a single line.
while [ find /tmp/file -mmin -1 >/dev/null -eq 0 ]; do
-eq doesn't work that way. Just drop the '[' and '-eq 0 ]' and it'll do what you want.
sleep 59 done else cp /tmp/file /somewhere fi
My attempt: while find /tmp/file -mmin -1 >/dev/null; do sleep 59 done cp /tmp/file /somewhere
Boyd, Yes, I want to sleep without copying the file, and when the condition was met (file is modified in the last minute) then stop sleeping and send. Here is a little something I just put together, and really thought it would work:
FILE=`find /tmp/file -mmin -1` while [ -e $FILE ]; do echo "I feel like sleeping" >/tmp/otherfile exit 1 done echo "Yay look" >/tmp/otherfile
But it doesn't continue the condition. I tried what you suggested and it also did about the same thing mine does. What I am looking for is: Keep searching for a certain file, and if it was modified in the last minute then copy it to another location, if it wasn't modified in the last minute, then sleep and check again in 58 seconds.
I took a different approach and the following worked intvl=$(($(date +%s) - $(stat -c %Y /tmp/file))) while [ $intvl -gt 60 ]; do echo "I feel like sleeping" sleep 5 intvl=$(($(date +%s) - $(stat -c %Y /tmp/file))) done echo "I worked for once" Using stat instead of find and comparing it to current time stamp. -- I say never be complete. I say stop being perfect. I say let's evolve. Let the chips fall where they may. -Fight Club -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (2)
-
Ben Kevan
-
Boyd Stephen Smith Jr.