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