dpkg-others

dpkg-query -S `which $1` | cut -d: -f1 | xargs dpkg-query -L

This command finds other files in the same debian package as a given executable.  I put it into a file called dpkg-others.  Example run:

/home/adyoung/bin/dpkg-others ODBCConfig
/.
/usr
/usr/bin
/usr/bin/DataManager
/usr/bin/DataManagerII
/usr/bin/ODBCConfig
/usr/bin/odbctest
/usr/share
/usr/share/doc
/usr/share/doc/unixodbc-bin
/usr/share/doc/unixodbc-bin/copyright
/usr/share/doc/unixodbc-bin/changelog.gz
/usr/share/doc/unixodbc-bin/changelog.Debian.gz
/usr/share/menu
/usr/share/menu/unixodbc-bin
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/ODBCConfig.1.gz

How to reset the root password on a GRUB based Linux boot

If you forget or somehow manage to change the root password on a machine running various flavors of glibc based security, and you are running a Linux kernel here are the steps to reset it.

  1.  Reboot the  machine.  This assume physical access, but reset the root password requires that anyway.
  2. At the GRUB prompt select the kernel you want and hit ‘e’ for edit.
  3. At the end of the kernel boot parameters add the word ‘single’.  This means boot into single user mode, and should bypass the need to type in a password.
  4. hit ‘b’ to boot.
  5. Once a Command prompt appears, use the passwd utility to reset the machine.
  6. Reboot.  Or, you can type ‘init 3’ or ‘init 5’ to complete the bot process.  Use 3 for servers, 5 for machines with graphical displays.

rpm and deb commands: files to packages and back

These two commands tell you which package owns a particular file for an RPM or DEB based system respectively.

rpmquery –whatprovides <path-to-file>

dpkg-query –search <path-to-file>

(The short form for dpkg is -S)

To list the files owned by a package use:

rpmquery –list <package>

dpkg-query -L <package>

(This long form for debian is –listfiles )

A useful utility to find all the other files in a package for a given binary (in this case lsof) is:

rpmquery –list $(rpmquery –whatprovides $(which lsof ) )

Or

dpkg-query -L $(dpkg-query –search $( which lsof ) | sed ‘s!\:.*!!’ )

extracting files from an rpm

rpms are saved in a file format called cpio, with a few minor changes.  To convert an rpm to this format use rpm2cpio.  The cpio binary is responsible for manipulating these files.  So if you want to treat that rpm as just another archive, and extract the files in it, you can link a couple of tools.  Here’s the line:

rpm2cpio your.rpm | cpio -di

If you don’t have arrays…but you have awk

A small project I have in the embedded side of things requires keeping track of information per index, what one would normally do in an array. However, the ash shell from busy box does not support arrays. Busybox does support awk. The following function is used to increment, decrement, and reset and array of counters of single digits stored as characters in a string.

#mod_field takes three parameters: OP INDEX DATA

#OP is the opperation: inc, dec, reset

#INDEX is the offset into the string from 1 to 9

#DATA is the state stored as a string

#OUTPUT is DATA with DATA[INDEX] modified

mod_field(){
OP=$1
INDEX=$2
DATA=$3

echo $OP $INDEX $DATA | \
awk ‘
{
VAL=substr($3,$2,1);
FIRST=substr($3,0,$2-1);
TAIL=substr($3,$2+1) ;
}
$1 ~ /inc/ { VAL++; }
$1 ~ /dec/ { VAL–; }
$1 ~ /reset/{ VAL=0; }
END{ print FIRST VAL TAIL;}

}

#Here is how to call it:
DATA=0000000000
DATA=`mod_field inc 3 $DATA `
echo $DATA

#This should produce 0010000000

DATA=`mod_field dec 3 $DATA `
echo $DATA

#And set DATA back to 0000000000
for i in 1 2 2 3 4 4 4 4 5 6 6 7 8 8 8 8 8 8 9
do
DATA=`mod_field inc $i $DATA `
done
echo $DATA
#Should produce 1214121610

for i in 1 2 2 3 4 4 4 4 5 6 6 7 8 8 8 8 8 8 9
do
DATA=`mod_field dec $i $DATA `
done
echo $DATA

#Should produce 0000000000

DATA=1111111111111
DATA=`mod_field reset 3 $DATA`
echo $DATA

#Should produce 0000000000