Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, September 23, 2008

Mounting Shares with Spaces

In linux sometimes you want to mount a windows share that has spaces in the name. This is actualy quite easy, just use \040 in place of the space

//ip.of.server/Home\040Folders/ejh /home/ejh/Documents cifs username=ejh,password=*****,uid=500,gid=500 0 0

Thursday, February 21, 2008

Finding Disk space Hogs

I occasionaly have a system go off the deep end eating up all of its space. This can be very difficult to track down. In order to find the offending files/directories goto the root and do
du -k -s * |sort -n
this will list the directories and files in the current directory in asc order so that the last one you see is the largest. Using this it is easy to move down the directory tree and quickly identify the offending files.

Using date in file name (and compressing files)

Yea this is stupid an easy, and also very annoying if you forget how!

    backup=`date +%Y%m%d`
tar czvf SQL-$backup.tar.gz *.sql
That backs up all the current .sql files in a directory into a file with todays date as the name

Deleting Files over Certain Age

The command to delete files over a certain age is deceptivly easy in linux.

   find * -mtime +5 -exec rm {} \;

That finds all files over 5 minutes old in the current directory. This is quite usefull in a backup script run from cron.

Tuesday, January 29, 2008

Setting TimeZone in linux

If you look in the /usr/share/zoneinfo directory you'll see all the available time zone settings. To change it just create a symlink from /etc/localtime to the correct zone file. (Reference)

mv /etc/localtime ~/localtime.old
ln -s /usr/share/zoneinfo/America/Denver /etc/localtime
If you want to sync your hardware clock run the following.
/sbin/hwclock  --systohc

Monday, January 28, 2008

Embedded vi Syntax Highlighting


This is a vi syntax highlighting trick gmax
emailed to me. It changes the syntax highlighting for here documents and the
qq() and q() operators as long as braces {} are used to delimit them (that is the trick, you see). This example
'embeds' the MySQL highlighting scheme inside Perl code. Example.


Find the perl.vim file that is being used by your version of vi, usually somewhere
in /usr/share/vim/


Add this syntax to it:


syn include @Sql <sfile>:p:h/mysql.vim
syn region perlSQL start="qq{" end="}" contains=@Sql keepend
syn region perlSQL start="q{" end="}" contains=@Sql keepend
syn region perlSQL start="<<MYSQL" end="^MYSQL" contains=@Sql keepend

just before this line at the end of the file:
let b:current_syntax = "perl"

and save this file [mysql.vim] to the same directory
as the file you just edited (perl.vim).


Configure Apt-get to use Web

I was having trouble with apt-get wanting a CD-ROM. This was inside a Nagios VMware appliance so I didn't have the CD. apt-get appears to default to using the cd, all you need to do is edit /etc/apt/sources.list and comment out the first line. Then uncomment one of the web address lines, in my file they where nicely commented so my final file looked like:


#deb cdrom:[Debian GNU/Linux 3.1 r1 _Sarge_ - Official i386 Binary-1 (20051218)]/ unstable contrib main
deb file:/root debs/
#deb http://security.debian.org/ stable/updates main contrib
deb http://debian.oregonstate.edu/debian/ stable main
#deb http://debian.oregonstate.edu/debian/ unstable main

A quick 'apt-get update' and I was in business.

Setting up Remote SSH with shared keys

This little bit of code is quite nice. I put it in a file called setup_ssh in my ~/bin directory and life was much easier. Now when I want to setup shared key authentication i just type 'setup_ssh user@host' and put in my password. Thats it!

#!/bin/bash
cat ~/.ssh/id_rsa.pub | ssh $1 'mkdir -p .ssh; cat >> .ssh/authorized_keys'