Category Archives: linux

How to disable-enable touchpad in ubuntu terminal

终端环境下可以通过以下命令来禁用/启用笔记本触控面板:

STEP 1: Determine the device id (the device name should be something with touchpad or glidepoint)

xinput list

STEP 2: Disable it (e.g. here the device id is 13)

xinput set-prop 13 "Device Enabled" 0

you can also dis/enable some other devices.
You may run the command during session startup

Original link: https://help.ubuntu.com/community/SynapticsTouchpad

libpcre.so.1: cannont open shared object file: No such file or directory.

after installed nginx, got some error message when raunch as: `/opt/nginx/sbin/nginx`

/opt/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

still i’m sure i’ve installed the latest pcre. and also i can find the libpcre.so.1 with:

find /usr/ -name "libpcre.so.1"
/usr/local/lib/libpcre.so.1

ok, why cannot found the libpcre.so.1 in `/user/local/lib` ??

strace /opt/nginx/sbin/nginx

So how does the dynamic loader know where to look for executables? As with many things on Linux, there is a configuration file in /etc. In fact, there are two configuration files, /etc/ld.so.conf and /etc/ld.so.cache. Note that /etc/ld.so.conf specifies that all the .conf files from the subdirectory ld.so.conf.d should be included.
Dynamic library configuration

ldconfig -p | grep "libpcre.so.1"

not found any matches.

so the problem is the dynamic loader not serach for my lib dir in /usr/local/lib

Then Use shared libraries in /usr/local/lib??

For the current session you can

export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

or to make the change permanent you can add /usr/local/lib to /etc/ld.so.conf (or something it includes) and run `ldconfig` as root.

keep reading. If not, read aboout ldconfig first.

after all, grep it:

ldconfig -p | grep "libpcre.so.1"
libpcre.so.1 (libc6,x86-64) => /usr/local/lib/libpcre.so.1

ok, got it!
run again /opt/nginx/sbin/nginx

that all..

these are some keyword need to read for details: `strace`, `ldconfig`, `/etc/ld.conf`, `/etc/ld.conf.cache`.

Input/Output Error: Bad Blocks: How To Restart Linux

-bash: /usr/bin/du: Input/output error

$ du
-bash: /usr/bin/du: Input/output error
$ reboot
bash: /sbin/reboot: Input/output error
$ shutdown -r now
bash: /sbin/shutdown: Input/output error

记得之前在sina的时候测试机也出现过类似的问题,当时是直接给运维同事电话重启了。。。

If the above reboot commands doesnot work try either forced reboot or shutdown

# Forced Reboot
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

# Forced Shutdown
echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger

see also for details

Upgrade Bash to 4+ on OS X and Use GNU Instead of BSD Command

Install latest bash

Install by brew for OS X user brew install bash

Compiling bash with source code: http://ftp.gnu.org/gnu/bash/

  • Add /usr/local/bin/bash to /etc/shells
  • Change the default shell with chsh -s /usr/local/bin/bash
  • To see your current version of bash do the following: echo $BASH_VERSION

Install and Use GNU Command Line Tools on Mac OS X

If you are moving onto Mac OS X from Linux, you would probably find out that the command line tools shipped with Mac OS X are not as powerful and easy to use as the tools in Linux. The reason is that Mac OS X uses the BSD version command line tools, which are different from the Linux version, while they are both compliant with POSIX standards.

  • Install the GNU Command Line Tools

    Get the latest GNU Coreutils and install to /usr/local/coreutils/

    wget http://ftpmirror.gnu.org/coreutils/coreutils-8.22.tar.xz
    tar xzf coreutils-8.22.tar.xz && cd coreutils-8.22
    ./configure --prefix=/usr/local/coreutils-8.22
    sudo make install
    sudo ln -sf /usr/local/coreutils-8.22 /usr/local/coreutils
    
  • Enable GNU coreutils, add coreutils bin folder to $PATH

    add script to .profile or .bash_profile

    export PATH="/usr/local/coreutils/bin:$PATH"
    

Links:

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

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:

#!/bin/bash

# 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

# 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

Example: 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

Reference from http://www.cyberciti.biz/tips/shell-root-user-check-script.html

The final version function checkRoot

checkRoot() {
    if [ "x$EUID" = "x" ] ; then
      EUID=`id -u`
    fi
    if [ "$EUID" != 0 ] ; then
      root=f
      case "`uname 2>/dev/null`" in
        CYGWIN*)
          # Cygwin: Assume root if member of admin group
          for g in `id -G 2>/dev/null` ; do
            case $g in
              0|544) root=t ;;
            esac
          done ;;
      esac
      if [ $root != t ] ; then
        echo "$self: You must run this as root" >&2
        exit 1
      fi
    fi
}

Create a socket proxy by ssh port forwarding

Enable TCP Forwarding by sshd server

cat /etc/ssh/sshd_config

Here are some example. First let’s restrict the users who are allowed to forward TCP sessions:

# SSH1, SSH2, OpenSSH
AllowTcpForwarding no

and then at the end of the file put

Match User allex,john,andy
    AllowTcpForwarding yes

Or better, allow specific ports per user groups:

AllowTcpForwarding no
Match Group admins
AllowTcpForwarding yes
Match User john,andy,ted
AllowTcpForwarding yes
PermitOpen 192.168.0.1:443

After all, restart openssh-server,

/etc/init.d/sshd restart

Use ssh -D port forwarding create a local socket proxy server

# Create socket proxy channel
ssh -CfNg -D 127.0.0.1:7070 user@host &>/dev/null &

Note: man ssh for more details,

  • -C Requests compression of all data
  • -f Requests ssh to go to background just before command execution.
  • -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
  • -g Allows remote hosts to connect to local forwarded ports (if just use local env AVOID IT)
  • -D Specifies a local “dynamic” application-level port forwarding.

Setup socket proxy in Browser.

There are lots of proxy tools for web browser extensions. (such as SwitchySharp for chrome.)

Use socks proxy for commands in terminal

export http_proxy=socks5://127.0.0.1:7070 https_proxy=socks5://127.0.0.1:7070

Reference Links

*nix find files by file size

*nix find 按文件大小查找文件:

-size

find {/path/to/directory/} -type f -size +{size-in-kb}k

如查找尺寸大于5M的mp3文件:

find /mp3collection -name '*.mp3' -size +5000k

查找尺寸小于1k的图片文件:

find . -size -1k

references:

http://www.codecoffee.com/tipsforlinux/articles/21.html

http://www.cyberciti.biz/faq/find-large-files-linux/

YUM Hangs And Won’t Respond

keyword: yum hangs and won’t respond

ssh 到测试机更新subversion1.7, 需要删除之前的老版本,发现yum命令没有响应,提示 “yum hangs and won’t respond”,
初步解决办法更新yum库缓存数据:

rm -f /var/lib/rpm/__*
rpm --rebuilddb -v -v   
yum clean all

If that did not work, you can set a debug level, error level and timeout for yum in /etc/yum.conf:

debugelevel=1
errorlevel=1
timeout=1

The timeout is standard 30 seconds. So if a repository does not respond, the error takes 30 seconds to appear. Also try using yum without the plugins (like fastest mirror and priorities) with the option –noplugins. Now starting yum again should give you more info faster. Test with:

yum --verbose --noplugins info

Creating .deb-Packages With Checkinstall and install nodejs

Checkinstall is a nice tool to create simple .deb-packages that you can use in your local network (e.g. if you have to install the same piece of software on multiple computers running Debian). It lets you compile and install software from the sources like before, but with the difference that you end up with a simple Debian package which also means that you can easily uninstall the software you just compiled by running:

dpkg -r pkgname

I will demonstrate the use of checkinstall by compiling and installing the anti-virus software ClamAV on a Debian system.
This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind!

1 Install Checkinstall

apt-get install checkinstall

2 Install nodejs latest

apt-get install python g++
mkdir ~/nodejs && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd `ls -rd node-v*`
./configure
# make install
checkinstall -D make install

This even works on the computer you compiled nodejs on! This is a nice way to install software from the sources and remove it if you are unsatisfied with the result.

NOTE: man dpkg for details pkg manager in ubuntu.

# install *.deb file
dpkg -i PACKAGENAME

# list all package installed
dpkg -l

# list files of a Debian package without install
dpkg --contents PACKAGENAME