Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (6) </ 1 2 3 [4] 5 6 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Beta testers needed, bash script testing< Next Oldest | Next Newest >
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Jan. 29 2008,18:23 QUOTE

Quote (^thehatsrule^ @ Jan. 29 2008,14:29)
Quote
I would also like to replace sed with awk if it can perform search & replace easily, like sed.
I'd stick with sed because it should be a 'lighter' binary (unless you have some reason to worry about having a missing sed)

Also, if you can, avoid using search and replace at all if possible.    For example, looking at your code in your first post, you can make a function that can print the output from variables instead of replacing the text in OUTPUT_FORMAT.

Yes. Just because of that. I've read that awk is more common than sed.
From Wikipedia:
Quote
A version of the AWK language is a standard feature of nearly every modern Unix-like operating system available today.
Quote
Besides the Bourne shell, AWK is the only other scripting language available in a standard Unix environment.

But now when you said that sed is lighter, I'll plan my script primary to look for sed, and then awk. =)

About for+case:
I think I have to stick with multiple cases. If I pass OUTPUT_FORMAT for for -loop to go trough and
then if/when sed/awk modifies it (still insife for -loop), for -loop won't know it's been modified. Right?
Then case inside for -loop might have to modify same information, bit in different place (in OUTPUT_FORMAT), more than once. Ok. Cituation like this is rare.Possible only is user has specified same spot (-UPTIME- for example) more than once.
With many case -sentences OUTPUT_FORMAT is modified instantly if any of the case -sentences is triggered.

Anyway tests that I performed showed very little difference, so I think this "performance tweaking" with for-case vs. many cases isn't really relevant anymore. I'd like to focus more to make this script to work on as many platforms/OSes as possible, meaning to make this use most common UNIX tools awailable.. ;) Many thanks anyway.

And I will need the search and replace because user running this script can specify his/her own output from the command line ie: ./sysinfo.sh "Uptime: -UPTIME- | Free RAM: -MEMFREE-"
Basically sed (maybe awk also) is there to search & replace user defined command line arguments.

Get it? ;)

Ok. Enough long post already. Brb going to moon.


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 29 2008,19:05 QUOTE

Quote
And I will need the search and replace because user running this script can specify his/her own output from the command line ie: ./sysinfo.sh "Uptime: -UPTIME- | Free RAM: -MEMFREE-"
Basically sed (maybe awk also) is there to search & replace user defined command line arguments.
How often are you going to use those custom lines?  If you really want to be somewhat more efficient you could only use sed/awk when you have custom lines instead (or somehow specify and eval given variables on the command line?).  It really depends on how much you want to spend on this.
Back to top
Profile PM 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Jan. 29 2008,19:39 QUOTE

That's true. It would be more efficient that way. It may be a bit complex to implement, but I'll try it some time. =)

--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Jan. 29 2008,20:07 QUOTE

New relase

Some if+grep statements still need to change.
And as usual, comments and suggestions are very welcome. ;)

Go to first post to get it


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Jan. 30 2008,13:04 QUOTE

Bug spotted.
It does not result to any error. But as I ran that script with bash -x I could see how it uses cat to get information from /proc even if specific information is already there. It makes this script slower. Even I have code to check if script already has the information needed, it still goes to fetch the information again.
Here's an example code where it fails to regonize that the data is already there:
Code Sample
   function parsememinfo {
       
       # Get memory information if there isn't already
       if [ -z "$MEMINFO" ]
       then
           MEMINFO=`cat /proc/meminfo`
       fi
       PARSED=${MEMINFO#*$*:}
       PARSED=${PARSED%% kB*}
       echo $PARSED
   }


Any of you have any solution to this?
First the code was like this: test -z $VARIABLE && VARIABLE="data"
and it didn't worked any better than the code above.


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
28 replies since Jan. 24 2008,16:16 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (6) </ 1 2 3 [4] 5 6 >/
reply to topic new topic new poll
Quick Reply: Beta testers needed

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code