[Lxc-users] small improvement to lxc scripts

-- NeoX -- exitneox at hotmail.com
Thu Jun 14 21:40:24 UTC 2012


Hi all,
did not you get annoyed by lxc-ls mixing available and running containers ?
here is my lxc-ls that put an echo before each category of container making life easier when using lxc-ls
simply replace the provided lxc-ls by this one (change are line 24 and 26 with 2 simples echo.
#!/bin/bash
lxcpath=/var/lib/lxc
if [ ! -r $lxcpath ]; then    exit 0fi
function get_cgroup(){        local mount_string        mount_string=$(mount -t cgroup |grep -E -e '^lxc ')        if test -n "$mount_string"; then                mount_point=$(echo $mount_string |cut -d' ' -f3)                return        fi        mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;        if test -z "$mount_string"; then                echo "failed to find mounted cgroup"                exit 1        fi        mount_point=`echo "$mount_string" |cut -d' ' -f2`;}echo "----- available containers -----"ls "$@" $lxcpathecho "-----  running containers  -----"active=$(netstat -xa 2>/dev/null | grep $lxcpath | \        sed -e 's#.*'"$lxcpath/"'\(.*\)/command#\1#');
if test -n "$active"; then        get_cgroup        if test -n "$mount_point"; then                # get cgroup for init                init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`                cd $mount_point/$init_cgroup/lxc                ls "$@" -d $active        fifi
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20120614/20b7cee7/attachment.html>


More information about the lxc-users mailing list