Montag, 25. Juni 2012

tomcat7 on Ubuntu 12.04 - access rights need change

After setting up tomcat, I deployed openam. The  initial configuration screen gave me "Configurator does not have write access to /usr/share/tomcat". It turns out that the user tomcat7 (who runs tomcat) has his home in /usr/share/tomcat7 (have a look at /etc/passwd). For some reason (bug?), this directory is owned by root, which made it unwritable for tomcat7. The fix is an easy (as root)

chown -R tomcat7:tomcat7 /usr/share/tomcat7

Donnerstag, 14. Juni 2012

Debian: Copy package selection to another system

The other day I moved to new desktop hardware and wanted to have all the packages that I had on my old desktop there. I made a package list of both systems with dpkg -l, put them together and then extracted the ones only present on one system with uniq. Then I looped over that list with for p in `cat packages.txt`;do apt-get install $p;done . Well, that worked, but it was rather tedious. I finally stumbled upon this mailling list post, which presented a much easier solution:

"
 To make a local copy of the package selection states: 

     $ dpkg --get-selections "*" >myselections   # or use \*

"*" makes myselections include package entries for "purge" too. 

You transfer this file to another computer, and install it there with: 

     # apt-get update
     # dpkg --set-selections <myselections
     # apt-get -u dselect-upgrade

"

Works like a charm!

Dienstag, 22. Mai 2012

experience with apache on opensuse 11.4

Today I had a apache webserver, which did not serve the page it was supposed to. It gave an "access denied" error. It turns out that the        
Options +FollowSymLinks
was in the <Location> block instead of the <Directory> block. Well. The funy thing was, that in order to let the configuration change take effect, a restart of apache was required. That is, I moved the Options thingy to the Directory block. But for checking I moved it back, and for that to take effect, a reload was enough. So for one change a restart is required, but for reversing the effect, a reload is enough. Strange, isn't it? (it took me hours to discover this, since I though a reload would be enough for both changes ...)

lpic 1 done

So finally I made it. If there is one piece of advice that is to be given: Read the objectives! Read the man pages of all the tools and files mentioned! Use all the tools and files at least once!

And: if you don't allready have a good background with X, don't spend too much time with it. There is plenty to know about it, but very little with relevance to the exam. If you do well in the other sections, you might just skip X.

Mittwoch, 25. April 2012

Preparing LPIC-1, #7 umask

The command 'umask' sets the default permissions on files and directories. The umask itself is specified as digits which are subtracted from the standard permissions maks, which is
  • 666 for files (that is rw-rw-rw-),  and
  • 777 for directories (that is rwxrwxrwx)
So if 'umask 002'  is specified, files will have standard permissins of 664 and directories will have 775.

'umask' without any parameters displays the currently set umask. If you give a parameter, 'umask' will interpret it as a umaks and set it. Thus you can change your umask by putting something like 'umask 022' in your .profile.

Mittwoch, 18. April 2012

Building a playground quota system on linux

I wanted to get a bit of experience using the linux quota system. I had no extra partition or disk at hand, so I created a virtual file system image. First I needed a file for this:

dd if=/dev/zero of=disc.img bs=1k count=100000

Then I created a partition table and a partition on it (not quite shure if this is really nessessary) using fdisk:

fdisk disc.img

Then I created a filesystem on my virtual partition:

mkfs.ext3 disc.img

ignoring the warning, that my disc.img is not a block device. Note that other filesystems would be possible, but  LPIC1 (for which I am currently preparing) does not require ext4 or btrfs which would be more modern filesystems. This might change soon though. I hear new exams are comming this summer.

Then I mounted it with the option for user quotas:

mkdir mnt
sudo mount  -o loop,usrquota disc.img mnt

Then I needed to create a quota file. This is a file wich resides at the root of the filesystem for which we want to use quotas. It can be done like this:

sudo quotacheck -u mnt/

This creates a  aquota.user file, which enables quotas for users. Now I set a quota


sudo setquota -u isaac 1000 10000 100 200 mnt/

following the syntax
 setquota -u user  <block-softlimit> <block-hardlimit> <inode-softlimit> <inode-hardlimit>

Bash filedescriptors and IO redirection with exec

The topic is very well covered in my favorite Bash-Scripting Guide. However, in a few examples they used something like the following code:

#!/bin/bash
# read a file line by line and echo it

filename=$1

exec 3<> $filename
while read line <&3
  do
  echo $line
done

exec 3>&-

The line "exec 3<> $filename" redirects the $filename to filedescriptor 3, which is then used as stdin in the next line. This example just uses input from the file, so I wondered why there was a "<>" instead of just "<", which would be sufficient for just reading the file. The reason is simple: Even though for this example it is not needed, the file is not only opened for reading, but also for writing, thus the ">". The last line "exec 3>&-" closes the file again.

We could modify the example to take advantage of the writing:

#!/bin/bash
# read a file line by line and echo it

filename=$1

exec 3<> $filename
while read line <&3
  do
  echo $line
done
echo another line >&3

exec 3>&-

This adds another line to the file given to the script as first argument. Its the "echo another line >&3" ( -- I should probably start using proper code highlighting ).