Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old July 23rd, 2002, 09:43 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
Filtering content in a shell script

I'm currently playing around with ways of changing the output from my SETI@Home client, as the standard outputs (nothing, or a long stream of all of the data) are a bit limited and annoying.

I've written a simple Perl script which takes the STDIN, runs it through a reg. exp looking for something like a percentage sign, then outputs lines with a percentage sign, so that it just outputs the completion percentages and not all the other data. What I'd like to do is use a shell script to do this, and also initialise the program, so it does something to this effect:

* start seti client
* take seti output, put through a reg exp, and output certain text on certain conditions

Can anyone give me a hand here?

Reply With Quote
  #2  
Old July 23rd, 2002, 10:23 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
if i were you, i would just put it all into the perl script:

to start seti and get the command output...try something like this:

open SETIOUTPUT,"/dir/where/seti/is/setiathome 2>&1|";


regex...


close SETIOUTPUT;

Reply With Quote
  #3  
Old July 23rd, 2002, 10:48 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
I could But I'n interested in how to do it in a shell script, rather than a Perl script. Thanks for the suggestion though

Reply With Quote
  #4  
Old July 23rd, 2002, 12:53 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
say the output is:

project seti@home process 10%

and you start the client with:
seticlient|myscript.sh

then myscript.sh should be:
Code:
#!/bin/sh
while read a,b,c,d; do
  echo $d
done;

looking at your actual wishes, you should make 2 scripts:
1. "start_seti.sh"
Code:
#!/bin/sh
/usr/local/bin/seti_client|filter_seti.sh

2. "filter_seti.sh":
Code:
while read line; do
  result=`echo $line|grep -e <regexp here>`
  case "$result" in
    *\%*)
      echo "$result percent done."
    ;;
    *ended*)
      echo "seti has ended."|mail user@localhost
    ;;
    *)
      echo "unknown result: $result from $line"
  esac
done;

untested, but should work
the asterisks are used as in good old dos, not regexps.

as you see, regexps are not supported by the shell, but grep and sed can do a great job!
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #5  
Old July 23rd, 2002, 01:02 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
Thanks, that's really cool I'll give it a go a little later. This is a good opportunity for me to finally try and get the hang of shell script syntax lol

Do you know if there's any way of doing it all in one shell script?

Reply With Quote
  #6  
Old July 23rd, 2002, 01:07 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
hmm. yes, there is. but i can´t remember the exact syntax and my linux machine still suffers from the harddrive breaking down

try this:

seti_client | while read line; do
... process messages here
done;

and the shell itself can do easy pattern matching / string manipulation (no regexps) like this:
$line="testing";

echo ${line%%in}
should output "test"
and:
echo ${line##in}
should output "g"

not sure about the #/%´s and their number (#, ##, %, %% are the four), i always mix them up since i don´t use it reguarly, but you can find out either rtfm´ing /usr/local/doc/packages/bash/bash_manual.html or just trying

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Filtering content in a shell script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway