Testing whether a string is null.

Testing whether a string is null.

#!/bin/bash
# str-test.sh: Testing null strings and unquoted strings,
#+ but not strings and sealing wax, not to mention cabbages and kings . . .

# Using if [ … ]

# If a string has not been initialized, it has no defined value.
# This state is called “null” (not the same as zero!).

if [ -n $string1 ] # string1 has not been declared or initialized.
then
echo “String “string1″ is not null.”
else
echo “String “string1″ is null.”
fi # Wrong result.
# Shows $string1 as not null, although it was not initialized.

echo
Continue reading “Testing whether a string is null.”

Strace – trace system calls and signals.

Strace is a useful diagnostic, instructional, and debugging tool. System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them. Students, hackers and the overly-curious will find that a great deal can be learned about a system and its system calls by tracing even ordinary programs. And programmers will find that since system calls and signals are events that happen at the user/kernel interface, a close examination of this boundary is very useful for bug isolation, sanity checking and attempting to capture race conditions.
Debugging why some process isn’t connecting to a remote server can be exceedingly frustrating. DNS can fail, connect can hang, the server might send something unexpected back etc. You can use tcpdump to analyze a lot of that, and that too is a very nice tool, but a lot of the time strace will give you less chatter, simply because it will only ever return data related to the syscalls generated by “your” process. If you’re trying to figure out what one of hundreds of running processes connecting to the same database server does for example (where picking out the right connection with tcpdump is a nightmare), strace makes life a lot easier.
Continue reading “Strace – trace system calls and signals.”

Wireless disabled by hardware switch

To get back your wifi, type in a terminal:

root# rfkill list

and then you will see something like this:

0: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: yes
1: hci0: Bluetooth
Soft blocked: no
Hard blocked: no

As you can see the phy0 is soft and hard blocked, so you need to unblock it:

root# rfkill unblock 0

or

root# rkill unblock all

and then press “Fn + F2” for a Dell laptop, and then restart your networking:

root# service network-manager restart

Install the spice-xpi on Debian wheezy or Ubuntu 12.04 LTS

To get the spice xpi working use the following steps:

1. Install the spice-client package which gives you /usr/bin/spicec
2. Extract the libnsISpicec.so file from the latest Fedora (FC19) spice-xpi RPM.
3. Placed it in /usr/lib/mozilla/plugins/
4. Restart Firefox.

After restarting Firefox, you can now view the console from RHEV/OVIRT.

Write ISO to USB stick.

After inserting your USB stick, you can find out what device it is using the following command:

grep -Ff <(hwinfo --disk --short) <(hwinfo --usb --short)

Finally, once you've found your block device, write the image to it. Point 'dd' to the full path such as '/home/user/Downloads/Linux-x86_64.iso'

umount /dev/sdX
dd if=/path/to/downloaded.iso of=/dev/sdX

Resizing images on Linux – ImageMagick convert command

With the resolution of today’s digital cameras it is often necessary to resize the files to make them smaller. You may want to reduce the file size before publishing them on the web, or sending in an email. There is however the convert command which is part of the ImageMagick suite. If you are running Linux then you most likely have that installed already, just man convert for more information. The most basic way to use convert is to give a file at a time on the command line:

convert -resize 50% original.jpg newsize.jpg

Alternatively you could replace the percentage with the actual size such as 640×480

convert -resize 640x480 original.jpg newsize.jpg

Where this really comes into it’s own is when you have a directory full of images that you want to convert. This can be used by using the xargs and find commands in conjunction with convert.

find . -iname "*.jpg" | xargs -l -i convert -resize 640x480 {} ../small/{}

Waiting for LDAP server to be ready – OES11

If you got this error while booting OES11: Waiting for LDAP server to be ready or namcd cannot connect to LDAP server in /var/log/messages please follow these steps:

cat /etc/nam.conf
--cut
base-name=o=users
workstation-context=o=servers
admin-fdn=cn=admin,o=users
preferred-server=172.16.10.77
--cut

and replace preferred-server to a correct IP, after change:

cat /etc/nam.conf
--cut
base-name=o=users
workstation-context=o=servers
admin-fdn=cn=admin,o=users
preferred-server=172.16.10.84
--cut

and then:

/var/lib/novell-lum # l
total 92
drwxr-xr-x 2 root root 4096 Nov 11 16:52 ./
drwxr-xr-x 43 root root 4096 Oct 30 10:15 ../
-rw-r--r-- 1 root root 1324 Oct 29 16:47 .172.16.10.77.der
-rw-r--r-- 1 root root 1324 Oct 30 10:29 .172.16.10.83.der

delete an old IP address
rm /var/lib/novell-lum/.172.166.10.77.der

and then refresh namcd:
namconfig cache_refresh
rcnamcd restart

How to use bind mounts in Linux.

Bind mounting is quite simple. Instead of mounting a block device into a particular path you are mounting one path into another path.

mount -o bind /home/andzia /ftp/andzia

You will now see this reflected when running the mount command:

mount | grep var
/home/andzia on /ftp/andzia type none (rw,bind)

If you want this to persist across reboots, you’ll just need to update your /etc/fstab with the bind mount as well.

/home/andzia /ftp/andzia none bind 0 0

Get a hardware information using a CLI.

Dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware. While this is a good point in terms of report speed and safe‐ness, this also makes the presented information possibly unreliable.


dmidecode |grep -i product