Categories

Blogroll

Syslog trick mudah.

Edit fail /etc/syslog.conf dan masukkan baris berikut

# dump semuanya pada tty8

*.* /dev/tty8

Skrip untuk melihat HOWTO yang dimampatkan(compressed)

Ini adalah contoh bagi howto yang terletak pada /usr/doc/faq/howto. Nama fail adalah seperti XXX-HOWTO.gz.

Buat satu fail yang dipanggil “howto” dalam direktori /usr/local/sbin

______________________________________________________________________

#!/bin/sh

if [ “$1? = “” ]; then

ls /usr/doc/faq/howto | less

else

gunzip -c /usr/doc/faq/howto/$1-HOWTO.gz | less

fi

______________________________________________________________________

Bila arahan howto diberikan tanpa argument ia akan memaparkan direktori yang menyimpan howto.

Untuk Melihat Serial-Howto misalnya, taip:

$ howto Serial

Adakah ruang kosong mencukupi??

Ini merupakan skrip yang kan memeriksa sama ada sistem mempunyai ruang kosong yang mencukupi. Sekiranya ruang kosong tidak cukup mesej akan dipaparkan setiap X saat pada konsol dan satu mesej berkaitan kekurangan ruang kosong yang tidak mencukupi.

______________________________________________________________________

#!/bin/sh

# bebaskan /tmp untuk ruang kosong

DEVICES=’/dev/sda2 /dev/sda8 /dev/sda9? # letakkan disini device anda

MINFREE=20480

SLEEPTIME=10

MAIL_TO_ME=’root@localhost’

MINMB=0

ISFREE=0

MAILED=””

let MINMB=$MINFREE/1024

while [ 1 ]; do

DF=”`/bin/df`”

for DEVICE in $DEVICES ; do

ISFREE=`echo $DF | sed s#.\*$DEVICE” “\*[0-9]\*””\*[0-9]\*” “\*## | sed s#” “.\*##`

if [ $ISFREE -le $MINFREE ] ; then

let ISMB=$ISFREE/1024

echo “WARNING: $DEVICE only $ISMB mb free.” >&2

#echo “more stuff here” >&2

echo -e “\a\a\a\a”

if [ -z “`echo $MAILED | grep -w $DEVICE`” ] ; then

echo “WARNING: $DEVICE only $ISMB mb free. (Trigger is set to $MINMB mb)” \

| mail -s “WARNING: $DEVICE only $ISMB mb free!” $MAIL_TO_ME

MAILEDH=”$MAILED $DEVICE”

MAILED=$MAILEDH

fi

elif [ -n “`echo $MAILED | grep -w $DEVICE`” ] ; then

MAILEDH=”`echo $MAILED | sed s#$DEVICE##`”

MAILED=$MAILEDH

fi

done

sleep $SLEEPTIME

done

Mencari direktori terbesar.

Untuk mencari direktori terbesar laksanakan arahan berikut

>du -S | sort –n

Mengelakkan sistem melakukan fsck setiap kali

>rdev -R /zImage 1

Ini akan meyakinkan sistem bahawa sistem tidak ditakrifkan sebagai dirty

Sekiranya anda mendapat ralat device busy semasa reboot

Pada /etc/rc.d/init.d/halt atau /etc/rc.d/rc.0, tambah baris berikut

mount -o remount,ro /mount.dir

Fail terbesar dalam harddisk

>ls -l | sort +4n

>cd /

>ls -lR | sort +4n

Cetak dokumen dengan margin untuk punching

#!/bin/sh

# /usr/local/bin/print

# a simple formatted printout, to enable someone to

# 3-hole punch the output and put it in a binder

cat $1 | pr -t -o 5 -w 85 | lpr

Proses yang mengambil paling banyak memori

>ps -aux | sort +4n

>ps -aux | sort +5n

Monday ~ November 11, 2007 by admin Posted in Linux Tips | No Comments

Sharing swap partitions between Linux and Windows.

 

1) Sharing swap partitions between Linux and Windows.

Tony Acero, ace3@midway.uchicago.edu

1. Format the partition as a dos partition, and create the Windows

swap file on it, but don’t run windows yet. (You want to keep the

swap file completely empty for now, so that it compresses well).

2. Boot linux and save the partition into a file. For example if the

partition was /dev/hda8:

dd if=/dev/hda8 of=/etc/dosswap

3. Compress the dosswap file; since it is virtually all 0’s it will

compress very well

gzip -9 /etc/dosswap

4. Add the following to the /etc/rc file to prepare and install the

swap space under Linux:

XXXXX is the number of blocks in the swap partition

mkswap /dev/hda8 XXXXX

swapon -av

Make sure you add an entry for the swap partition in your /etc/fstab

file

5. If your init/reboot package supports /etc/brc or /sbin/brc add the

following to /etc/brc, else do this by hand when you want to boot

to dos|os/2 and you want to convert the swap partition back to the

dos/windows version:

swapoff -av

zcat /etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100

# Note that this only writes the first 100 blocks back to the parti-

tion. I’ve found empirically that this is sufficient

>> What are the pros and cons of doing this?

Pros: you save a substantial amount of disk space.

Cons: if step 5 is not automatic, you have to remember to do it by

hand, and it slows the reboot process by a nanosecond :-)

2) Desperate Undelete. Michael Hamilton, michael@actrix.gen.nz

Here’s a trick I’ve had to use a few times. Desperate person’s text file undelete. If you accidentally remove a text file, for example, some email, or the results of a late night programming session, all may not be lost. If the file ever made it to disk, ie it was around for more than 30 seconds, its contents may still be in the disk partition. You can use the grep command to search the raw disk partition for the contents of file.

For example, recently, I accidentally deleted a piece of email. So I immediately ceased any activity that could modify that partition: in this case I just refrained from saving any files or doing any compiles etc. On other occasions, I’ve actually gone to the trouble of bring the system down to single user mode, and unmounted the filesystem. then used the egrep command on the disk partition: in my case the email message was in /usr/local/home/michael/, so from the output from df, I could see this was in /dev/hdb5

sputnik3:~ % df

Filesystem 1024-blocks Used Available Capacity Mounted on

/dev/hda3 18621 9759 7901 55% /

/dev/hdb3 308852 258443 34458 88% /usr

/dev/hdb5 466896 407062 35720 92% /usr/local

sputnik3:~ % su

Password:

[michael@sputnik3 michael]# egrep -50 ‘ftp.+COL’ /dev/hdb5 > /tmp/x

Now I’m ultra careful when fooling around with disk partitions, so I paused to make sure I understood the command syntax BEFORE pressing return. In this case the email contained the word ‘ftp’ followed by some text followed by the word ‘COL’. The message was about 20 lines long, so I used -50 to get all the lines around the phrase. In the past I’ve used -3000 to make sure I got all the lines of some source code. I directed the output from the egrep to a different disk partition – this prevented it from over writing the message I was lookingfor.I then used strings to help me inspect the output strings /tmp/x | less Sure enough the email was in there. This method can’t be relied on, all, or some, of the disk space may have already been re-used.

This trick is probably only useful on single user systems. On multiusers systems with high disk activity, the space you free’ed up may have already been reused. And most of use can’t just rip the box out from under our users when ever we need to recover a file. On my home system this trick has come in handy on about three occasions in the past few years – usually when I accidentally trash some of the days work. If what I’m working survives to a point where I feel I made significant progress, it get’s backed up onto floppy, so I haven’t needed this trick very often.

Monday ~ November 11, 2007 by admin Posted in Linux Tips | No Comments