Tuesday, August 7, 2012

System information commands in Linux

General CPU Information

$cat /proc/cpuinfo

Processor Utilization

$sudo apt-get install sysstat
$mpstat -P ALL

Memory Information/Usage

$cat /proc/meminfo

Network Startistics


Security camera in Ubuntu

Using Motion you can setup a security camera using an ordinary web camera and Ubuntu.
1. First we need to install Motion.

$sudo apt-get install motion

2. Insert the USB camera and check if was properly detected.

Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0ac8:301b Z-Star Microelectronics Corp. ZC0301 Webcam

3. Edit /etc/motion/motion.conf and specify the target directory where to dump the images and videos. Also enable daemon mode.

# Start in daemon (background) mode and release terminal (default: off)
daemon on


# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /home/jachermocilla/motion

4. Start the Motion daemon.

$sudo /etc/init.d/motion start

5. Sample output from the setup is shown below.

6. The above setup works if we have plenty of disk space. If we have limited disk space, we need to delete some old files from target_dir. This script does just that. However, we need to make some customization in the script because it works using the df command.


   USAGE=`df -h | grep "$MOUNT" | awk '{ print $5 }' | sed s/%//g`


   USAGE=`du "$MOUNT" | awk '{ print $1 }' | sed s/M//g`

7. Run the script on a separate terminal.

$chmod u+x deleteoldfiles.sh
$./deleteoldfiles.sh /home/jachermocilla/motion 40000