Tag Archive for 'bash'

Miracle patch out-performed by four lines of bash

Well it’s nothing if not interesting. The ~200 line “miracle” patch promises a huge improvement in desktop responsiveness, but Lennart Poettering (from Red Hat) has replied to Linus’ praising comments with 4 lines of bash which out-perform it, on the current vanilla kernel. (And by the way, Lennart seems to agree with Con Kolivas about this patch, in that make -j is not a valid desktop use case.)

Lennart said:

Binding something like this to TTYs is just backwards. No graphical
session has a TTY attached anymore. And there might be multiple TTYs
used in the same session.

I really wonder why logic like this should live in kernel space at all,
since a) the kernel has no real notion of a session, except audit and b)
this is policy and as soon as people have this kind of group then they
probably want other kind of autogrouping as well for the other
controllers, which hence means userspace is a better, and configurable
place for this.

To which Linus then replied:

Numbers talk, bullshit walks.

The numbers have been quoted. The clear interactive behavior has been seen.

And you’re just full of bullshit.

Come back when you have something working and with numbers and better
interactive performance. Until then, nobody cares.

So, Lennart replied with his something better, 4 lines of bash:

Here’s my super-complex patch btw, to achieve exactly the same thing
from userspace without involving any kernel or systemd patching and
kernel-side logic. Simply edit your own ~/.bashrc and add this to the end:

if [ "$PS1" ] ; then
mkdir -m 0700 /sys/fs/cgroup/cpu/user/$$
echo $$ > /sys/fs/cgroup/cpu/user/$$/tasks
fi

Then, as the superuser do this:

mount -t cgroup cgroup /sys/fs/cgroup/cpu -o cpu
mkdir -m 0777 /sys/fs/cgroup/cpu/user

Done. Same effect. However: not crazy.

Of course the debate raged on because Linus thinks it’s stupid to make people have to set this up in userspace, and Lennart disagrees. Despite all this, finally everyone is at least acknowledging these issues and looking into them! Excellent.

-c

Script for configuring ClamAV server on Fedora

In short, I’ve written a bash script (available from github) for configuring and removing instances of clamav-server on Fedora. It lets you create and remove individual instances with a specific user and port (if you specify them) and will install the required packages if not already present on the system.

In long, we use Clam AntiVirus as our antivirus protection for Digital Preservation Recorder and talk to it over the default port, 3310.

Installing the clamav-server package under Fedora however, doesn’t actually set up an instance. In fact, it doesn’t copy any system configuration files into place at all. This means that the system is left without any working ClamAV server out of the box.

Under Fedora, ClamAV server is configured on a per user basis. This is actually quite important (unless you run as root) because the daemon needs at minimum read access (and we’ve found also write) on the files/directory being passed for scanning.

The instructions on how to configure it are located under /usr/share/doc/clamav-server-[version]/ but I have taken these instructions and written a bash script to configure all of this for you.

The script is available from github. It can create or remove an individual instance of clamav-server using a specific username and port (if you want to specify them, else it defaults to clamav on port 3310). The script will also install any required packages, if you don’t already have them on the system.

Hopefully this is useful to someone else out there and not just us :-) If you find any bugs feel free to let me know.

Fedora with sudo bash completion

By default Fedora does not enable sudo access for any user (other than root). Most administration tasks require the root password, however it’s simple to add your user to the sudoers file and run commands as root. Great.

However, one thing which is annoying is lack of bash completion support when running the sudo command. I like using tab completion, however if I preface anything with the sudo command, it doesn’t work.

It’s easily solved by running the following as your user:
complete -cf sudo

Yay!

From Fedora 11 onwards, both /sbin and /usr/sbin are in the user’s path by default.

Sed off

I’m sure many are familiar with the general substitute method of sed for replacing something in a file, i.e. sed -i s/this/that/g ~/myfile but recently I wanted to replace an entire line in a file, using bash.

I wanted to modify the localhost entry in /etc/hosts to include the static hostname too, all tab delimited. This is how I did it.
sed -i /^127.0.0.1/c\127.0.0.1\\t`hostname -f`\\t`hostname`\\tlocalhost.localdomain\\tlocalhost /etc/hosts

Find the line that begins with 127.0.0.1 and replace it with itself, plus the result of the hostname commands, etc. This gives me a line like so:

127.0.0.1   pc.fqdn   pc   localhost.localdomain   localhost

I’m sure someone else knows a much more efficient way of doing this, but oh well, it works :-)

-c