sispmctl – using it as non root

Hello,
in my article sispmctl English I worked as root all the time. I would prefer to use “sispmctl” as normal user (and without sudo). My solution is to change the group of the entry for the power outlet in /dev/usbdev* to “plugdev”.

(By the way, this “hack” was created and tested on a Debian Lenny system.)

Check if the user is a member of the group plugdev:

crissa@unseen:~$ grep crissa /etc/group
[...]
plugdev:x:46:crissa
[...]

If your user isn’t a member of the group “plugdev” you can add him with “adduser plugdev”.

Get more information about the power outlet:

unseen:~# lsusb -v
[...]
Bus 001 Device 027: ID 04b4:fd13 Cypress Semiconductor Corp. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04b4 Cypress Semiconductor Corp.
  idProduct          0xfd13
  bcdDevice            1.01
  iManufacturer           1 Gembird Electronics
  iProduct                2 Gembird Silver Shield PM
 [...]

The ipVendor and idProduct can be used to identify the power outlet.

Add an entry to the file local.rules in the directory /etc/udev/rules.d:

# 20110105 crissa  sispmctl
SYSTEM=="usb", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="fd13", GROUP="plugdev"

# eof

I prefer to create an extra file for my own entries.

Restart udev to load the new udev rules:

unseen:~# /etc/init.d/udev restart
Stopping the hotplug events dispatcher: udevd.
Starting the hotplug events dispatcher: udevd.

Check /dev/usbdev* for a plugdev entry:

unseen:~# ls -l /dev/usbdev* | grep plugdev

Plug in the power outlet and check again:

unseen:~# ls -l /dev/usbdev* | grep plugdev
crw-rw---- 1 root plugdev 252, 8 2011-01-05 22:22 /dev/usbdev1.28_ep00

The final test as (non root) user:

crissa@unseen:~$ sispmctl -m all
Accessing Gembird #0 USB device 028
Power supply status is: off
Power supply status is: off
Power supply status is: off
Power supply status is: off
crissa@unseen:~$ sispmctl -o 1
Accessing Gembird #0 USB device 028
Switched outlet 1 on
crissa@unseen:~$ sispmctl -m all
Accessing Gembird #0 USB device 028
Power supply status is: on
Power supply status is: off
Power supply status is: off
Power supply status is: off

Feel free to create a new group (maybe “sispmctl”) for the power outlet user. I don’t need an extra group so the group “plugdev” is fine with me, at least for now.
Bye, Tore

Posted in General, Linux | Tagged , , , , | Leave a comment

dpkglist

Hello,
last weekend I was helping a friend to check his Ubuntu system. With the command line

crissa@unseen:~$ dpkg --list | grep -v "^ii"  | tail -n+6

I found a lot of not complete removed packets. It was a long list, but we didn’t count them. The command “dpkg –list” shows the installed packets and their install status. With “grep -v “^ii”” I filter the correct installed packets and with “tail -n+6” I remove the first 5 lines from the top of the output. (On my Debian system called unseen all packets are correct installed.)

After I removed squid (with “apt-get remove squid” as root) on another system called lostin I got this output:

crissa@lostin:~ ssh$ dpkg --list | grep -v "^ii" | tail -n+6
rc  squid          2.4.6-2woody8  Internet Object Cache (WWW proxy cache)

The head of the output of “dpkg –list” shows what is the meaning of the status “rc”:

crissa@lostin:~ ssh$ dpkg --list | head
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================

The package is in the status “remove” and “config-files”. For a package that has no install problems you will find the status “ii”, “install” and “installed”. So far I only saw the status “ii” and the status “rc” on my systems.

I already added the command “dpkg –list | grep -v “^ii” | tail -n+6″ to my crontab, but for my friend I was looking for a better solution:

#!/bin/sh
# dpkglist
# 20110104 crissa for http://blog.rotten.li

dpkg --list |

awk '
{
  if ($1 ~ /^\+\+\+/) {
    head = 1;
    next;
  }
  if (head) {
    print $0;
  } else {
    next;
  }
}
' |

awk '
{
  sum++;

  status[$1]++;

  if ($1 !~ /^ii/) {
    cnt++;
    line[cnt]=$0;
  }
}
END {
  print "---------";

  for (x in status) {
    printf "%-3s  %4d\n",  x, status[x];
  }

  printf "sum  %4d\n", sum;

  print "---------";

  for (x=1; x<=cnt; x++) {
    print line[x];
  }

  if (cnt) print "---------";
}
'

# eof

This script doesn’t use temporary files (read Safely Creating Temporary Files in Shell Scripts English for more information about the problems with temporary files). The script is checking which lines to skip. It looks for any status and not just “ii” and “rc”. And it counts the lines:

crissa@lostin:~ ssh$ dpkglist
---------
rc      1
ii    679
sum   680
---------
rc  squid          2.4.6-2woody8  Internet Object Cache (WWW proxy cache)
---------

This script can be started as normal user so I added it to my user crontab:

crissa@unseen:~$ crontab -l
# m h  dom mon dow   command
07 07 * * 0 /usr/local/bin/dpkglist

The script is running every Sunday (the “0” under dow => day of week) at 7 minutes past 7 (the “7” under m => minute and the “7” under h => hour). See cron – Wikipedia, the free encyclopedia English for more information.

At last I removed squid with “dpkg –purge squid ; cd /var/cache ; rm -rf squid/” from the system lostin.

After my friend removed all the packets with the status “rc” some problems he had with his Ubuntu system were solved. I had the same experience with one of my systems, after I did some packet uncluttering logrotate was working again.

If you have strange problems on you system a little check with this script wouldn’t harm. But keep in mind that removing the wrong packets could do great harm. So be careful, you have been warned!
Bye, Tore

Posted in General, Linux | Tagged , , , , | Leave a comment

Is There Anybody Out There?

Hello,
while searching for a way to get the information if there is still someone connected to a Cisco router (without connecting myself) I found How To Get Information About Users Connected To The TTY By Using SNMP English.

I added some configuration to the router:

access-list 60 remark protect snmp
access-list 60 permit 192.168.1.0 0.0.0.255
!
snmp-server community private RW 60
snmp-server community public RO 60

Beware: The community strings are an example and shouldn’t be used on real equipment or outside a test lab!

While I was connected (from another session) to the console port of the router I tried to look for tsLineActive (that means: actice lines on the router).

crissa@unseen:~$ snmpwalk -v 2c -c public 192.168.1.250
  1.3.6.1.4.1.9.2.9.2.1.1
SNMPv2-SMI::enterprises.9.2.9.2.1.1.0 = INTEGER: 1
SNMPv2-SMI::enterprises.9.2.9.2.1.1.1 = INTEGER: 0
SNMPv2-SMI::enterprises.9.2.9.2.1.1.2 = INTEGER: 0
[...]

Double check on the router.

router#who
    Line       User       Host(s)              Idle       Location
*  0 con 0     cisco      idle                 00:00:00   

  Interface    User               Mode         Idle     Peer Address

But I just need the value of the used ports.

crissa@unseen:~$ snmpwalk -v 2c -c public 192.168.1.250
  1.3.6.1.4.1.9.2.9.2.1.1 | grep "INTEGER: 1" | wc -l
1

If you know how to ask it is easy to get the information you need! Without SNMP the only way to get this information is to connect to the router and to use the command “who” or “show user”.
Bye, Tore



Posted in Cisco, General | Tagged , , , | Leave a comment

The CBT Nuggets App and the problem of the secure password

Hello,
I use a CBT Nuggets English account to watch their training videos on their website. (My employer paid for the license.) So I watched their training videos at home or at work or somewhere else on my iPhone using Safari. But I couldn’t use the CBT Nuggets App English as I couldn’t log in. I always got an error message (something like “Wrong username or password!”). Today I had the idea to change my password and to remove a special character from it. And … it worked! Now I can watch their traing videos on my iPhone just using the App.

I already sent a mail to CBT Nuggets and they know about the problem and think to add it to the FAQ. What about fixing it and update the App?
Bye, Tore

Watching a training video with the CBT Nuggets App.

Posted in General, iPhone | Tagged , , , , | Leave a comment

sispmctl

Hello,
sispmctl is the name of a program to control a Gembird SIS-PM programmable power outlet. It is controlled from a Windows PC over an USB cable. A Gembird SIS-PM power outlet with 4 sockets costs around 30 € (here in Germany). With the power outlet comes a driver for Windows, but there is help if you want to use it with a Linux box: SIS-PM Control for Linux English.

With Debian Lenny the installation is easy.

unseen:~# apt-get install sispmctl

The first task was to scan for a power outlet:

unseen:~# sispmctl -s
Gembird #0 is USB device 019.This device is a 4-socket SiS-PM.
Accessing Gembird #0 USB device 019
This device has a serial number of 01:02:03:04:05

My power outlet was beeping from time to time, so my second task was to switch off the beeper:

unseen:~# sispmctl -b off
Accessing Gembird #0 USB device 019
Turned buzzer off

Third task: Test the power outlet and do some switching!

#!/bin/sh
# sis_tst.sh

while [ TRUE ]
do
  sispmctl -q -f 1      # switch socket 1 off
  sispmctl -q -g 1      # check socket 1 status
  sleep 15              # wait 15 seconds
  sispmctl -q -o 1      # switch socket 1 on
  sispmctl -q -g 1      # check socket 1 status
  sleep 15              # wait 15 seconds
done

# eof

The light is on!

The outcome:

unseen:~# ./sis_tst.sh
off
on
off
on
off
[...]

The advantage of this power outlet: It is cheap. The disadvantage: It needs a computer to control it. (With the Windows program you can setup timers, some people use it to control their fish tank lights. I didn’t install nor tried the Windows software.)

My Linux box is running all the time. But there is other equipment that I only need from time to time …
Bye, Tore

Posted in General, Linux | Tagged , , , | Leave a comment

alive

Hello,
sometimes it would be helpful if ping would just answer with “alive” (=> “Yes, I could ping it”) or “not alive” (=> “No answer while I was waiting”). A simple “0” (=> “alive”) or “1” (=> “not alive”) would be useful in a script.

This short shell script called “alive” is all we need:

#!/bin/sh
# alive

ping -c 1 -w 3 "$1" &>/dev/null
echo $?

# eof

Testing the script:

crissa@unseen:~$ alive 111.222.333.444
2
crissa@unseen:~$ alive 192.168.1.77
1
crissa@unseen:~$ alive 192.168.1.88
0

2 => error => no valid ip address
1 => not alive => valid ip address, no answer
0 => alive => valid ip address, successful ping

This shell script will use alive:

#!/bin/sh

if [ `alive $1` == "0" ]
then
  echo "$1 is alive"
else
  echo "$1 is not alive"
fi

# eof

Maybe the following would be easier to use:

#!/bin/sh

if ping -c 1 -w 3 "$1" &>/dev/null ;
then
  echo "$1 is alive"
else
  echo "$1 is not alive"
fi

# eof

Choose what ever suits your needs. ;-)
Bye, Tore

Posted in General, Linux | Tagged , , , | Leave a comment

Embedder

Flag United KingdomHello,
on my “static” sites I use the Website Meta Language English to create macros. To create the HTML code for a language that is used on a linked website I simply type <flag de> or <flag gb>.

With the WordPress plugin Embedder English I can achieve nearly the same. Embedder even supports PHP code. But as my PHP knowledge is limited I only created some shortcuts to mark the language that is used on a linked website. So with WordPress I have to use [flag_de] or [flag_gb] for the moment.

In the past I got the flag images from the World Flag Database English. But they only allow the use of up to four images from their database on a website. A source without this limitation is Free World Flags English. This site only ask for a link back to their site to use the flag images. That was easy! By the way, I scaled the flag images down to 16×10 for better use in a text like this.
Bye, Tore



Posted in General, WordPress | Tagged , , , , , | Leave a comment

Backup

Hello,
this is the fifth posting.

Q: Why should I consider a backup?

On my static web sites a backup is easy. I create a *.tar file and copy it to another disk. Done. With a WordPress site I have to save some files and (of course) the database.
I found this documentation: Backup einer WordPress Installation German
This documentation mentions a WordPress Plugin: WP-DB-Backup English
The installation was fast and easy, I only had to set the permission of the backup directory.

A: I should consider a backup because the installation of a backup plugin is easy. Starting all over again is a lot of work. Not to mention the time I spend to create the postings and the pictures.
Bye, Tore

Posted in General, WordPress | Tagged , , | Leave a comment

Merry christmas and a happy new year!

Hello,
and greetings from Dortmund, Germany!
Bye, Tore

Posted in General | Leave a comment

favicon

Hello,
to create the favicon images for my sites I use IcoMaker for Mac OS X English Japanese. For this blog I only created the 16×16 and 32×32 icons, it seems that IcoMaker has a problem with 48×48 icons. I didn’t look deeper into it, but I think I used to many colors.

To add the favicon.ico to this site I followed the Creating a Favicon English documentation on the WordPress Codex English site.

The last step was to check the new favicon with the Favicon Validator English.
Bye, Tore

Posted in General, WordPress | Tagged , , , | Leave a comment