|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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? ![]() |
|
#2
|
||||
|
||||
|
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; |
|
#3
|
||||
|
||||
|
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 ![]() |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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 lolDo you know if there's any way of doing it all in one shell script? |
|
#6
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > Filtering content in a shell script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|