LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Bash script - technical question

[ILUG] Bash script - technical question

David Pintor painterman at gmail.com
Sat Oct 30 17:05:03 IST 2010


Hi,

Thanks for your responses... :-)

Just in case anyone's interested, I found a more or less nice way to do
this, using a file that stores the seconds and using both sleep and the
crontab...

Basically:

if interval >= 1 min
   sleep ` cat secs.txt`
   get info > logfile
   next_date=`date +interval`
   echo "next_date * script" > crontab
   get seconds from next date > secs.txt
else # less than 1 minute
   if this is the first time i run the script
       put entry in the crontab for next minute # it will take a few secs to
start
   else
       while true
           sleep secs
           get info > logfile
       done
    fi
 fi


Regards,

David


On 29 October 2010 18:04, Brian Foster <blf at utvinternet.ie> wrote:

>  > Date: Fri, 29 Oct 2010 12:24:23 +0100
>  > From: Pádraig Brady <P at draigBrady.com>
>  >[ ... ]
>   > Note sleep on linux supports hours etc. like:
>  >
>  >   wait=1:2:3
>  >   sleep $(echo $wait | sed 's/\([^:]*\):\([^:]*\):\(.*\)/\1h \2m \3s/')
>
>  Heh.  I'd just do:
>
>    wait=1:2:3
>    sleep $( IFS=:; set -- $wait; echo $1h $2m $3s )
>
>  Above assumes $wait always has the three ‘:’-separated fields
>  HH, MM, and SS.  If an issue, it's easily modified to handle
>  missing/empty fields:
>
>    sleep $( IFS=:; set -- $wait; echo ${1:-0}h ${2:-0}m ${3:-0}s )
>
>  And you don't _need_ the GNU/Linux sleep(1) feature being used,
>  you could just compute the number of seconds....  but that's a
>  different (and probably not relevant) observation.
>
> cheers!
>        -blf-
> --
> “How many surrealists does it take to    |  Brian Foster
>  change a lightbulb?  Three.  One calms  |  somewhere in south of France
>  the warthog, and two fill the bathtub   |     Stop E$$o (ExxonMobil)!
>  with brightly-coloured machine tools.”  |       http://www.stopesso.com
> --
> Irish Linux Users' Group mailing list
> About this list : http://mail.linux.ie/mailman/listinfo/ilug
> Who we are : http://www.linux.ie/
> Where we are : http://www.linux.ie/map/
>


More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell