Tag Archive for 'script'

Find out what is using your swap, by Erik Ljungstrom

Ever wondered what it is that’s using that swap on your machine? Erik has a great post about it and a script that will help answer that question.

Here is his script:
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0
 
done
echo "Overall swap used: $OVERALL"

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.

Changing priorities

I’m scripting some sys admin tasks in Debian which require the installation of packages like Postfix. I don’t want it to prompt me with questions, so I knew I had to set the priority to something higher for this specific package (i.e. temporarily). There doesn’t appear to be a way to pass this to an apt-get command (which was a little disappointing) but debconf can set it system wide under /var/cache/debconf/config.dat, but that’s, well, ugly.

Turns out there’s an environment variable you can set to achieve what I want, DEBIAN_PRIORITY. So exporting this variable and unsetting it post install will do the trick, but I still think apt-get -p critical install postfix would be better :-)

-c