Samstag, 7. März 2009

How much energy does that steak have?

While studying for the second part of the LPIC 1 Certificate(LPI102), I started messing about with bash scripts. I still way prefer python, but bash is handy to whip together semi useful stuff quickly.
Anyhow, this script quite ineffeciently gets the kilocalorific (kcal) value of (some) foods:
#!/bin/bash
searchterm=$1
data=$(curl -# 'http://www.med-surfer.de/kalorientabelle/kalorientabelle.php3')
echo $data | egrep -i "
.*
" | sed -e "s/<\/td>/<\/td>\n/g" | egrep -i "value='.*kcal.*'>" | sed -e "s/.*value='//g" | sed -e "s/'><\/td>$//g" | sed -e "s/\.\+/ /g" | sed -e "s/kcal/kcal pro 100g hat/g" | iconv -f iso-8859-1 | grep -i $searchterm
Of course, you can see immediately that this is limited to the html formatting on the page above - which in turn means you have to enter your query auf deutsch. Furthermore, you could probably reduce the number of times that sed is called significantly. And you could grep more than just one foodstuff quite easily either. But this at least helped to get me up to speed for the 102.
By the way, everything after the echo $data above is on one single line - the blog format might split it up. Otherwise, do:
  1. wget http://www.foxhall.de/downloads/kal.sh
  2. chmod +x kal.sh
  3. ./kal.sh apfel
I'd be interested in hearing how I could improve it - not what the script does, but how it does it - e.g. reducing the numbers of grep and sed calls.

Montag, 2. März 2009

LPI 102 Objectives by weight

LPI 102 Objectives, sorted by weight

1
1.107.2 Manage printers and print queues
1.107.3 Print files
1.107.4 Install and configure local and remote printers
1.108.5 Notify users on system-related issues
1.114.3 Setup user level security

3
1.105.2 Reconfigure, build and install a custom kernel and kernel modules
1.106.1 Boot the system
1.106.2 Change runlevels and shutdown or reboot system
1.108.2 Find Linux documentation on the Internet
1.109.2 Customize or write simple scripts
1.111.3 Configure and use system log files to meet admin and security needs
1.111.5 Maintain an effective data backup strategy
1.112.4 Configure Linux as a PPP client
1.114.2 Setup host security

4
1.105.1 Manage/Query kernel and kernel modules at runtime
1.108.1 Use and manage local system documentation
1.111.1 Manage users and group accounts and related system files
1.111.2 Tune the user environment and system environment variables
1.111.4 Automate system admin tasks by scheduling jobs to run in the future
1.111.6 Maintain system time
1.112.1 Fundamentals of TCP/IP
1.113.1 Configure and manage xinetd, inetd and related services
1.113.2 Operate and perform basic configuration of Mail Tranfer Agent (MTA)
1.113.3 Operate and perform basic configuration of Apache
1.113.4 Properly manage the NFS and SAMBA daemons
1.113.5 Setup and configure basic DNS services
1.113.7 Set up secure shell (OpenSSH)
1.114.1 Perform security administration tasks

5
1.109.1 Customize and use the shell environment

7
1.112.3 TCP/IP configuration and troubleshooting