While you can always parse /proc/meminfo, there’s system call sysinfo which does the trick.

While you can always parse /proc/meminfo, there’s system call sysinfo which does the trick.

I always knew that ’sort’ command has ‘-k N’ flag which tells to sort based on columns N,…. I just recently find out that this flag is even more versatile, and it can be used as ‘-k N,M’ which will sort based on columns N,…,M. As usuall, it’s in the man page, but i always missed it so far
.
I’m disappointed by choice of Linux distributions for my EeePc (called pingu). I installed Ubuntu EEE there which works, however, because of specifically built kernel, i cannot find/compile modules for VirtualBox which i really need. It looks like main stream distributions are Mandriva (which is supposed to work, but i personally don’t like it), EeeDora & Ubuntu EEE. There are a lot of smaller distros which all work partly on the Eee and require tweaking in order to make them usuable.
While i use ArchLinux at home, it’s too much work to install it on the Eee and maintain it working, i’d like to have something more stable and less attention requiring.
I do not intend to whine about open source software quality and choice, because i very much appreciate the choice, freedom of it and free time that a lot of people devte to it. I’m looking for advice.
What are you using on your Eee
?
Update: ubuntu eee (temporary name) 8.10 will be released 1.1.09. Extremely exciting news!
Overflow in shell script… while it sounds strange, it actually happened to me
. I have a script which does recoding of mp3 files in order to reduce bitrate and space those files take. I tried to be smart and first detect the bitrate in order to avoid redundant recoding. Well, my script actually worked for a long time, but then it refused to recode file with bitrate 256
.
It was my fault of course. In order to determine the bitrate, i used the following ash function:# function to determine bitrate:
# expects a file as parameter
determine_birate() {
if [ -z “$1″ ]
then
return 0 # invalid
fi
if [[ “${MP3INFO}” == “” ]]
then
return 1 # invalid
fi
return `”${MP3INFO}” -p “%r” “$1″`
}
MP3INFO is an application i use in order to read mp3 files meta data. Well, when the bitrate was 256 i got 0 returned, i guess bash has some limit of 1 byte somewhere
. My quick fix was (and now it works great):# function to determine bitrate:
# expects a file as parameter
determine_birate() {
if [ -z “$1″ ]
then
return 0 # invalid
fi
if [[ “${MP3INFO}” == “” ]]
then
return 1 # invalid
fi
echo `”${MP3INFO}” -p “%r” “$1″`
}
….
CURRENT_BITRATE=`determine_birate “$file”`
Let’s assume that you are working in a relatively small organization, 4-5 hundreds people at most. I’m sure you have some kind of intranet and there’s a phone book there. I’m pretty sure you have a page with most used phone numbers pinned on your wall somewhere.
Here’s idea how to search those phones from command line. The solution is based on two scripts. First downloads the names list and formats it as necessary (mine strips all HTML mumbo-jumbo). This one is called periodically by cron. Second is used for names list search.
Here are the scripts:
update_tel_db#! /bin/sh
cd /your/path/to/database
wget http://your.path.here/file.here >& /dev/null
touch tel.txt ; \rm tel.txt
links -dump file.here | grep @ | grep -v — ——————– | grep -v mailto | grep -vi ‘Click here’ | grep -v javascript | grep -v IMG | grep -v file: | tr ‘|’ ‘ ‘ | sed ’s/^ *//’ | sed ’s/ / /g’ | sed ’s/\[[0-9]*\]//g’ > tel.txt
\rm file.here >& /dev/null
touch tel.txt
tel#! /bin/bash
echo ‘NAME DPT OFFICE CELL-PHONE HOME E-mail’
grep -i $1 /tour/path/here/tel.txt
Now telephone search becomes tel name on the command line.
Enjoy
I wrote about changing of certain columns in a file, but here let’s solve a simpler task. I’d like to add something, let’s say date, to every line of a file. I’ll emulate a file using `seq 1 10`.
The following is easy enough:seq 1 10 | awk '{print "echo `date` "$0}' | bash
However, there’s simpler solution:seq 1 10 | while read ; do echo `date` ${REPLY} ; done
It works because REPLY variable is set to the line of input read by the read builtin command when no arguments are supplied (from bash manpage).
Recently, i had a problem - i needed to run several utilities in parallel in bash script, wait till they finish and then gather the information they produced. It’s sooooooooo easy!
Bash has ‘wait’ command which… (surprisingly) waits for all (or certain) background processes to finish. Knowing that, the rest is easy.
Here’s a bash script which simulates utilities with ’sleep’ command.
nParallelTasks=10
nStartedTasks=0
for i in `seq 1 100`
do
echo "-- $i --"
sleep 5&
nStartedTasks=$(($nStartedTasks + 1))
if [[ "$nStartedTasks" == "$nParallelTasks" ]]
then
echo "waiting"
wait
nStartedTasks=0
fi
done
bash.org.ru is bash.org in russian
. Here’s one citation i felt i must translate (original in russian):
<@insomnia> u have to execute three commands to install Gentoo
<@insomnia> cfdisk /dev/hda && mkfs.xfs /dev/hda1 && mount /dev/hda1 /mnt/gentoo/ && chroot /mnt/gentoo/ && env-update && . /etc/profile && emerge sync && cd /usr/portage && scripts/bootsrap.sh && emerge system && emerge vim && vi /etc/fstab && emerge gentoo-dev-sources && cd /usr/src/linux && make menuconfig && make install modules_install && emerge gnome mozilla-firefox openoffice && emerge grub && cp /boot/grub/grub.conf.sample /boot/grub/grub.conf && vi /boot/grub/grub.conf && grub && init 6
<@insomnia> that’s first.
Technorati Tags: bash.org, bash.org.ru, linux, gentoo, joke
I wanted to call this “advanced awk”, but it’s in fact simple idea with awk and bash integration. I got this idea from wonderful ArchLinux forums.
The problem is as follows. Given a file with several columns, i want to run a command on some columns and keep other columns as is.
For example, given a file with user names and some more information, i need to convert user names to user ids and keep other information unchanged. Example file is:
The desired result is:root a b c
ftp d e f
0 a b c(of course, user id of ‘root’ is 0 and of ‘ftp’- 14)
14 d e f
cat myFile | awk '{print "echo \"$(id -u "$1") " $2 " " $3"\""}'cat myFile | awk '{print "echo \"$(id -u "$1") " $2 " " $3"\""}' | bash
Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers