Friday, September 19, 2008

scheduling a task to automatically run using cron

To get cron to automatically run something, it must be listed in a crontab file. Each user has his own crontab file. To edit a user's crontab file, use the command crontab -e (a crontab file will be created if none exists).

An entry in a crontab file looks like this:

m h dom mon dow command

where m = minutes, h = hours, dom = day of month, mon = month, and dow = day of week. cron will automatically run the specified command whenever the time matches the specified time. To indicate "any", use an asterisk (*). So to get something to run at 5pm every day, you would add the following line to your crontab file:

00 17 * * * cmd-name

Make sure to use crontab -e to edit your crontab file. The actual files are stored in /var/spool/cron/crontabs/, but you shouldn't edit those files directly.

Pasted from wikipedia:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
 *  *  *  *  *  command to be executed

Update 2012-08-13: still can't get cron working (Lucid)

This page provided some hints: http://aplawrence.com/Unixart/crontab_not_running.html

/var/log/syslog did not show the cron jobs running

chkconfig --list | grep cron indicated that cron was off:

cron                      0:off  1:off  2:off  3:off  4:off  5:off  6:off

Saturday, September 13, 2008

Setting apache web server

Install: sudo apt-get install apache2

Basically followed guidelines here.

The main thing I had to do was to create my own public_html directory, and create an apache config file pointing to it.

1) Create config file at /etc/apache2/sites-available/ (copy /etc/apache2/sites-available/default config file)
2) edit config file to point to created public_html directory
3) create public_html/cgi-bin directory if needed and modify ScriptAlias section of config file to point to created directory
4) disable apache default site: sudo a2dissite default
5) enable new site: sudo a2ensite (verify in /etc/apache2/sites-enabled/)
6) restart apache server: sudo /etc/init.d/apache2 restart

Conky system monitor

After briefly looking around for a linux system monitor, I decided to install Conky (over GKrellM and some others).

Getting started is really easy. All I did was copy someone else's .conkyrc file. Check here, here, here, or here.

Conky allows all sorts of customizations. The conky man page is really useful, as is this page describing all the available variables in conky.

Here is what my conky window ultimately looked like:



Here is what my .conkyrc file wound up looking like:

# UBUNTU-CONKY
# A comprehensive conky script, configured for use on
# Ubuntu / Debian Gnome, without the need for any external scripts.
#
# Based on conky-jc and the default .conkyrc.
# INCLUDES:
# - tail of /var/log/messages
# - netstat connections to your computer
#
# -- Pengo (conky@pengo.us)
#

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# fiddle with window
use_spacer none
use_xft yes
xftfont Vera Sans:size=8

# Update interval in seconds
update_interval 3.0

# Minimum size of text area
minimum_size 650
maximum_width 650

# Draw shades?
draw_shades no

# Text stuff
draw_outline no # amplifies text if yes
draw_borders no
#font arial
uppercase no # set to yes if you want all text to be in uppercase

# Stippled borders?
stippled_borders 3

# border margins
border_margin 9

# border width
border_width 10

# Default colors and also border colors, grey90 == #e5e5e5
default_color grey

own_window_colour brown
own_window_transparent yes

# Text alignment, other possible values are commented
#alignment top_left
#alignment top_right
alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 5
gap_y 50

# stuff after 'TEXT' will be formatted on screen

TEXT
${color green}SYSTEM ($sysname $kernel) ${hr 2}$color
Uptime:$color $uptime Load:$color $loadavg $processes processes ($running_processes running) Logged In: $user_number

${color green}CPU (Intel Core2 Quad Q6600 @ $freq_g GHz)${hr 2}$color
CPU Temp: ${platform w83627ehf.656 temp 1}C MB Temp: ${platform w83627ehf.656 temp 2}C CPU Fan: ${platform w83627ehf.656 fan 2} RPM Case Fan: ${platform w83627ehf.656 fan 1} RPM PSU Fan: ${platform w83627ehf.656 fan 3} RPM

${color orange}Core 1:$color${goto 70}${platform coretemp.0 temp 1}C${goto 139}${cpu cpu1}%${goto 175}${color orange}Core 2:$color${goto 240}${platform coretemp.1 temp 1}C${goto 303}${cpu cpu2}%${goto 340}${color orange}Core 3:$color${goto 405}${platform coretemp.2 temp 1}C${goto 468}${cpu cpu3}%${goto 505}${color orange}Core 4:$color${goto 570}${platform coretemp.3 temp 1}C${goto 635}${cpu cpu4}%
${cpugraph cpu1 40,150 000000 ffffff}${goto 175}${cpugraph cpu2 40,150 000000 ffffff}${goto 340}${cpugraph cpu3 40,150 000000 ffffff}${goto 505}${cpugraph cpu4 40,150 000000 ffffff}

${color blue}${goto 80}CPU USAGE${goto 400}MEMORY USAGE$color
NAME${goto 125}CPU%${goto 175}MEM%${goto 300}NAME${goto 400}MEM%${goto 455}MEM (PHY)${goto 525}MEM (VIRT)
${top name 1}${goto 125}${top cpu 1}${goto 175}${top mem 1}${goto 300}${top_mem name 1}${goto 400}${top_mem mem 1}${goto 455}${top_mem mem_res 1}${goto 525}${top_mem mem_vsize 1}
${top name 2}${goto 125}${top cpu 2}${goto 175}${top mem 2}${goto 300}${top_mem name 2}${goto 400}${top_mem mem 2}${goto 455}${top_mem mem_res 2}${goto 525}${top_mem mem_vsize 2}
${top name 3}${goto 125}${top cpu 3}${goto 175}${top mem 3}${goto 300}${top_mem name 3}${goto 400}${top_mem mem 3}${goto 455}${top_mem mem_res 3}${goto 525}${top_mem mem_vsize 3}
${top name 4}${goto 125}${top cpu 4}${goto 175}${top mem 4}${goto 300}${top_mem name 4}${goto 400}${top_mem mem 4}${goto 455}${top_mem mem_res 4}${goto 525}${top_mem mem_vsize 4}
${top name 5}${goto 125}${top cpu 5}${goto 175}${top mem 5}${goto 300}${top_mem name 5}${goto 400}${top_mem mem 5}${goto 455}${top_mem mem_res 5}${goto 525}${top_mem mem_vsize 5}

${color green}MEMORY / DISK ${hr 2}$color
RAM:${goto 100}$mem / $memmax${goto 285}$memperc%${goto 340}Swap:${goto 450}$swap / $swapmax${goto 620}$swapperc%
${membar 8,300}${goto 340}${swapbar 8,300}

Root:${goto 80}${fs_used /} / ${fs_size /}${goto 220}(${fs_free /} free)${goto 340}Home:${goto 410}${fs_used /home/username/} / ${fs_size /home/
username/}${goto 550}(${fs_free /home/username/} free)
${fs_bar 8,300 /}${goto 340}${fs_bar 8,300 /home/username/}
Movies:${goto 75}${fs_used /misc/} / ${fs_size /misc/}${goto 220}(${fs_free /misc/} free)${goto 340}TV:${goto 400}${fs_used /tv/} / ${fs_size /tv/}${goto 550}(${fs_free /tv/} free)
${fs_bar 8,300 /misc/}${goto 340}${fs_bar 8,300 /tv/}

${color green}NETWORK (${addr eth0}) ${hr 2}$color
Down: ${downspeedf eth0} k/s${goto 120}Total: ${totaldown eth0}${goto 240}Inbound: ${tcp_portmon 1 32767 count}${goto 340}Up: ${upspeedf eth0} k/s${goto 450}Total: ${totalup eth0}${goto 560}Outbound: ${tcp_portmon 32768 61000 count}
${downspeedgraph eth0 40,300 000000 ffffff}${goto 340}${upspeedgraph eth0 40,300 000000 ffffff}

Wednesday, August 13, 2008

gcc compiler error when compiling C files: error: stdlib.h: No such file or directory

Trying to compile nrg4iso (http://code.google.com/p/nrg4iso/), I discovered that gcc does not seem to be properly installed. After some searching, I discovered that this is the problem:

http://ubuntuforums.org/showthread.php?t=441404
http://ubuntuforums.org/showthread.php?p=2642484#post2642484

The C compiler is actually split into two packages. The actual compiler (gcc) is packaged separately from the C libraries and header files (libc6-dev). To compile a typical C program, you must install both of these packages. A frequent source of confusion is installing just gcc without libc6-dev. This gives you the compiler, but none of the standard header files.

There is a "meta-package" called build-essential that depends on these packages, along with g++, make and dpkg-dev. So a quick way to get the core C/C++ compiler and libraries is to give the command:

sudo apt-get install build-essential

Saturday, July 26, 2008

How to change the default size of the terminal window in ubuntu

Use the --geometry option in gnome-terminal. So I changed the command of my Terminal launcher to be:

gnome-terminal --geometry=80x48

Friday, July 25, 2008

Setting up an ssh / sftp server in ubuntu

Using OpenSSH: http://www.openssh.com/

sudo apt-get install openssh-server


More information here:
https://help.ubuntu.com/community/SSHHowto
http://tombuntu.com/index.php/2008/02/19/installing-and-using-a-ssh-server/

Edited config file at /etc/ssh/sshd_config and set:
PermitRootLogin no
AllowUsers
Port #####

This site has good tips on SSH server security.

Command to restart ssh server:

sudo /etc/init.d/ssh restart

Setting up SFTP logging:

1) edit /etc/ssh/sshd_config
2) on the line Subsystem sftp /usr/lib/openssh/sftp-server, add a "-l VERBOSE" flag. So the entire line should look like:

Subsystem sftp /usr/lib/openssh/sftp-server -l VERBOSE

SFTP activity will be logged to /var/log/auth.log. For more logging options, see http://www.openbsd.org/cgi-bin/man.cgi?query=sftp-server&sektion=8

Wednesday, July 16, 2008

Sunday, July 13, 2008

Choosing a mouse and keyboard for my HTPC

For input devices for my HTPC, I decided to go with the Gyration Cordless Optical Air Mouse and Compact Keyboard Suite (GC1105CKM). Both the mouse and keyboard connected and worked with Ubuntu Hardy Heron right out of the box. The only thing I needed to setup was the additional mouse buttons and multimedia keyboard keys.

To utilize the extra buttons, I followed the directions here and used xbindkeys:
http://perens.com/works/software/gyration.html

1) I first created an .xbindkeysrc file in my /home directory

xbindkeys --defaults > /home/stchang/.xbindkeysrc

2) I ran xbindkeys-config and added the three additional mouse buttons using the "New" and "Get Keys" buttons in xbindkeys-config

3) For the Command box, I used xvkbd -xsendevent to execute the key sequence that I wanted. For now I have the buttons mapped to do forward/rewinding in vlc:
button3: xvkbd -xsendevent -text "\C\[Left]"
button4: xvkbd -xsendevent -text "\A\[Left]"
button5: xvkbd -xsendevent -text "\C\[Right]"

Saturday, June 14, 2008

How to move the /home directory to a separate partition (ie - a separate hard drive)

When ubuntu installs, the home directory is created on the same partition as the os. However, it would be nice to move the home directory to its own partition so that the os can be reinstalled/upgraded without affecting user files. Here's how I did it.

1) Create a new partition (see previous post about how to format and mount a second hard drive)
2) Mount new partition using mount (mount to anywhere except /home)
3) Copy user directories in /home to new partition
4) Delete everything in /home (but keep the actual /home directory)
5) Edit /etc/fstab to have new partition mount to /home
(note that you may have to update the UUID of the new partition in /etc/fstab, see previous post about adding an entry to /etc/fstab)
(another note, if the mount fails, when you try to login, you will get an error that says that the user directory cannot be found)

Saturday, June 7, 2008

How to share files (installing samba)

Sharing files and folders in ubuntu over a network is extremely easy. Simply right click on any folder and choose "Sharing Options". When the Folder Sharing windows comes up, simply select the "Share this folder" option. If samba is not installed, you will be prompted with a message that says "You need to install the Windows networks sharing service in order to share your folders". Choose "Install service" option and samba will be installed automatically (it seems like the packages that get installed are samba and samba-common).

That's it! Just reboot and everything should work. Note that if you don't reboot, you'll get the following error message:

'net usershare' returned error 255: net usershare add: cannot convert name "Everyone" to a SID. The connection was refused. Maybe smbd is not running.

How to monitor CPU temperature in linux

I followed the instructions found here:
http://www.xawk.com/ubuntu-cpu-temperature.html

I installed the lm-sensors package using the command:

sudo apt-get install lm-sensors

I then ran the sensors-detect executable:

sudo sensors-detect

I used all the default answers to the questions (typically, yes) except for the last one where it asked if I wanted to modify /etc/modules (no was the default but I entered yes). The following lines were added to /etc/modules:

# Chip drivers
w83627ehf
coretemp

I then rebooted and tried to install X Sensors but it kept saying that coretemp and
w83627ehf were not supported by xsensors.

So next I turned to sensors-applet:

sudo apt-get install sensors-applet

I also installed hddtemp:

sudo apt-get install hddtemp

to get hard drive temperatures (choose yes when it asks if you want to run a daemon).

To run the applet, right click on any panel and choose "Add to Panel" and then add the "Hardware Sensors Monitor". Right click on the applet and select Preferences -> Sensors to choose what information is displayed.

Friday, June 6, 2008

Getting DVDs to play in linux

After some brief research, I decided to use the Ogle DVD player because it supports menus.

I installed ogle and ogle-gui using apt-get:

sudo apt-get install ogle
sudo apt-get install ogle-gui

I installed libdvdcss2 from Medibuntu, following instructions from here:
https://help.ubuntu.com/community/Medibuntu

First I added the Medibuntu packages to my package manager:
sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update

Then I installed libdvdcss2 using apt-get:

sudo apt-get install libdvdcss2

And it worked! (after a reboot)

MPlayer also works for playing DVDs (after installing libdvdcss2) but doesnt support menus.


Note that before installing libdvdcss2, I was getting the following error when trying to play DVDs with Ogle:
libdvdread: Can't open file VIDEO_TS.IFO.
ERROR[ogle_nav]: faild to read VIDEO_TS.IFO
DVDSetDVDRoot:: Root not set

This error was fixed after I installed libdvdcss2

Wednesday, June 4, 2008

Changing the ownership of a directory or file

use the chown command: chown username dirname

Owner of a directory can be queried using ls -l (3rd column)

chgrp changes the group of a directory. Group name is the 4th column in the results of ls -l

Tuesday, June 3, 2008

Formatting a hard drive in linux

I got 2 hard drives for my system. Seagate 7200.10 Barracudas, 250gb each. The first one was formatted and the partitions were created (ext3 file system) during the ubuntu install. However, I couldn't figure out how to format the second one.

After a bit of searching, I found a couple of ways to do it. The first is to use fdisk and mkfs: http://www.ehow.com/how_1000631_hard-drive-linux.html

The second is to use gparted. I chose to use gparted because it has a gui. I first selected the drive I wanted (/dev/sdb) and created a disklabel (I used the "msdos" table type). I then created a primary partition (ext3 filesystem) by choosing Partition -> New from the menus.

After hitting "Apply", the partition was created in a few seconds. Pretty easy.

Next I edited /etc/fstab to get the drive to automatically mount on startup. I added the following line to my fstab file:

UUID=41a557bc-3f4f-4cc9-8edf-c32672529897 /stuff ext3 relatime,errors=remount-ro 0 1

where the relatime,errors=remount-ro options are the same as my main drive.

I chose to mount by UUID instead of device name in case I wind up swapping the drives around. In order for the mount by UUID to work, I first had to add a symbolic link in /dev/disk/by-uuid/ for the partition I just created.

I found the UUID of the partition using the vol_id command:

sudo vol_id /dev/sdb1

I then created the symbolic link in /dev/disk/by-uuid/ using the ln command:

sudo ln -s ../../sdb1 41a557bc-3f4f-4cc9-8edf-c32672529897

where sdb1 is the partition I just created and 41a557bc-3f4f-4cc9-8edf-c32672529897 is the UUID returned by vol_id

Which version of linux?

My system has an Intel Core 2 Quad Q6600 processor and an Asus P5E-VM HDMI mainboard. This board uses the Intel G35 chipset and I'm using the integrated video. This machine will be used as a media server in my house.

I decided to use Ubuntu on my system. I didn't really spend too much time deliberating. I chose ubuntu because it seems to be the easiest to use for a linux noob like me. I'm using the 64 bit desktop edition of version 8.04 (Hardy Heron).

First Post

I'm currently building a new computer system and, for the first time, I will be using only linux as the operating system. The purpose of this blog is to document this process. I am a complete linux noob, so the problems I run into may seem obvious to many, but hopefully others that find themselves in a similar situation can benefit from my experiences.