Register
It is currently Fri Jul 25, 2014 12:46 am

HELP! Read number of lines in a .txt file and IF statement


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Aug 05, 2009 2:02 pm   

Joined: Wed Aug 05, 2009 1:56 pm
Posts: 1
Firstly appologies, I imagine this isn't the done thing but I've been working non-stop on something for 6 days and now the Mrs. is giving me ear-ache, (I'm sure you've all been there) so......

Could somebody please write me a bash script to do this:

Wait for 1 minute
count the number of lines in a .txt file and if > 10 then play a .wav file
loop

This is something I want to run from boot, constantly

It shouldn't be too difficult for you seasoned pro's so I hope you don't mind

Thanks very much


Top
 Profile  
 PostPosted: Wed Aug 05, 2009 3:01 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Code:
#!/bin/bash
file=$1
player=mpg123
wavefile="wavefile.wav"
while [ true ]; do
    num=$(cat $file | wc -l)
    if [ $num -gt 10 ]; then
        $player $wavefile
    fi
    sleep 60
done


usage: ./script file-to-monitor.txt
Just change the mpg123 to your desired player, and change wavefile.wav to the absolut path of the wave file.

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP