IBM / Lenovo Computer Print Serial Number and Other Information from a Shell Command Prompt

Posted on in Categories Hardware, Howto, Linux, Linux desktop, Linux laptop last updated January 4, 2008

If you are a proud owner of IBM / Lenovo laptop / desktop computer use vpddecode command to print the “vital product data” information without opening your case or rebooting the system. This information is hardcoded on almost all IBM and Lenovo computers BIOS. It will show following information:

=> BIOS Build ID
=> Box Serial Number
=> Motherboard Serial Number
=> Machine Type/Model
=> BIOS Release Date
=> Default Flash Image File Name

Command to display BIOS information

WARNING! These examples only works on IBM/Lenovo Computer or Laptop systems

Open terminal and type the following command as the root user:

$ sudo vpddecode
OR
# vpddecode

How to: Check the bash shell script is being run by root or not

Posted on in Categories CentOS, Debian Linux, FreeBSD, Linux, RedHat/Fedora Linux, Shell scripting last updated January 6, 2008

Sometime it is necessary to find out if a shell script is being run as root user or not.

When user account created a user ID is assigned to each user. BASH shell stores the user ID in $UID variable. Your effective user ID is stored in $EUID variable. You can

Old way…

You can easily add a simple check at the start of a script:

Check the script is being run by root user

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

New way: Using EUID

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

Mount /dev/sdb1 only if you are a root

#!/bin/bash
if [[ $EUID -ne 0 ]]; then
  echo "You must be a root user" 2>&1
  exit 1
else
  mount /dev/sdb1 /mnt/disk2
fi

Updated for accuracy and more examples.

Ubuntu Linux Restore admin / root level permissions

Posted on in Categories Tips, Troubleshooting, Ubuntu Linux, User Management last updated November 1, 2007

I was writing and testing few python scripts (yes I’m moving lot of stuff from shell / perl to python these days) and accidentally I renamed my own user account from vivek to test. However, I did not noticed change until I rebooted my box. Now I cannot run sudo (or become a root user) and cannot access special devices such as sound or video.

By default your first account has all power via sudo under Ubuntu Linux. There is a special group called adm and admin which grants unlimited power via sudo.

The only solution was to boot computer in emergency mode (reboot computer and at grub menu select recovery mode kernel), open /etc/group file and add user vivek to admin and adm group:
# vi /etc/group
Add user vivek to admin and adm group:
admin:x:117:vivek
adm:x:4:vivek

Save and close the file.

Now I’m able to run sudo and do other stuff. Luckily, my scripts always backup critical files before modification. So I was able to restore permission instantly. Here is my group membership with all power and glory ;)
$ id
$ groups

Output:

vivek adm dialout cdrom floppy audio dip video plugdev scanner netdev lpadmin powerdev admin

Linux Gnome desktop: Open files as root via a right click (context menu option)

Posted on in Categories Gnome, Howto, Linux, Linux desktop last updated October 2, 2007

Windows XP has a small option called Run as command.. You can add similar option to Linux desktop to open or run file as root via a right click. The following tutorial explains how to add a context menu item that enables a Linux user to open files as the root user when browsing their file system using nautilus. This script feature allows the user to navigate their file system and open or edit any file or directory as the root user of the system. It’s a perfect solution for those that are not completely comfortable using terminal commands.

=> How to open files as root via a right click

nixCraft FAQ Roundup April 27, 2007

Posted on in Categories FAQ last updated October 30, 2008

Recently updated/posted Linux and UNIX FAQ (mostly useful to Linux/UNIX new administrators or users) :

Enjoy!