Thursday, February 18, 2010

Basic SVN Commands

http://www.linuxfromscratch.org/blfs/edguide/chapter03.html#ch03-propset

Find out runlevel of unix or Linux system

A runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init command/process for each of these runlevels are defined in the /etc/inittab file. Runlevels 0, 1, and 6 are reserved. Runlevel 0 is used to halt the sys tem, runlevel 6 is used to reboot the system, and runlevel 1 is used to get the system down into single user mode. In order to print current runlevel you need to use command who or runlevel as follows:

1) Print print current runlevel using who command:

$ who -r

run-level 2  Dec 16 11:45                   last=S
2) Find the current and previous system runlevel using runlevel command:

$ runlevel

N 2 

Runlevel reads the system utmp file (typically /var/run/utmp) to locate the runlevel record, and then prints the previous and current system runlevel on its screen. Runlevel can be used in rc scripts as a substitute for the System-V who -r command. However, in newer versions of init this information is also available in the environment variables RUNLEVEL and PREVLEVEL:

$ echo $RUNLEVEL
$ echo $PREVLEVEL

Source: http://www.cyberciti.biz/howto/question/linux/unix-linux-find-out-runlevel.php

Linux change the runlevel for a server without rebooting

Q. How do I change the runlevel for a Linux server without rebooting my server? I am using Gentoo Linux.

A. Almost all Linux distribution use init program to change runlevel. init is the parent of all processes. Its primary role is to create processes from a script stored in the file
/etc/inittab . This file usually has entries which cause init to spawn gettys on each line that users can log in. It also controls autonomous processes required by any particular system.

To change runlevel from 3 to 1 you need to type command as follows:
# init 1
OR
$ sudo init 1

Where 1 is runlevel number, other possible runlevel values are:
=> 0 - Shutdown server
=> 1 - Take server to single-user mode
=> 2 - Start X Window (used by Debian)
=> 3 - Full multi-user text mode
=> 5 - Start X Window
=> 6 - Reboot server


Source: http://www.cyberciti.biz/faq/change-the-runlevel-for-a-linux-server/

Changing runlevels

More Information on Runlevels: http://en.wikipedia.org/wiki/Runlevel

Wednesday, February 17, 2010

Execute a command without saving it in the history

$command
This is sample output - yours may be different.
$ echo this goes to history
this goes to history

$ echo this wont go to history
this wont go to history

$ history
1 echo this goes to history
2 history

Monday, February 8, 2010

Twittering with UBUNTU

http://jamsubuntu.blogspot.com/2009/03/twittering-with-ubuntu.html

Sunday, February 7, 2010

Running Scripts on Shutdown and Startup

Running Script at time of shutdown
=========================

myscript:

#!/bin/sh
echo `date`>>/home/vamshi/Desktop/vvvshut.txt
exit 0

the script should begin with #!/bin/sh called as "shebang" line

file is saved as
  • file.sh in /etc/init.d/
  • K10file.sh in /etc/rc0.d/
  • K10file.sh in /etc/rc6.d/
then executable permissions are given in all directories with command

chmod +x file.sh

that's it, Script executes on shutdown.


Running Script at time of startup
=======================

Script is same, but now i need to execute at startup and may be write to a different file about the startup time.

For this just put that script in /etc/rc.local file.

This file will execute at the time of startup and make that script
run for you

Mindblowing

http://blog.insicdesigns.com/2010/02/mind-blowing-javascript-experiments/

Saturday, February 6, 2010

Probe Overhead

On a typical CPU in use in 2005, a kprobe hit takes 0.5 to 1.0
microseconds to process. Specifically, a benchmark that hits the same
probepoint repeatedly, firing a simple handler each time, reports 1-2
million hits per second, depending on the architecture. A jprobe or
return-probe hit typically takes 50-75% longer than a kprobe hit.
When you have a return probe set on a function, adding a kprobe at
the entry to that function adds essentially no overhead.

Here are sample overhead figures (in usec) for different architectures.
k = kprobe; j = jprobe; r = return probe; kr = kprobe + return probe
on same function; jr = jprobe + return probe on same function

i386: Intel Pentium M, 1495 MHz, 2957.31 bogomips
k = 0.57 usec; j = 1.00; r = 0.92; kr = 0.99; jr = 1.40

x86_64: AMD Opteron 246, 1994 MHz, 3971.48 bogomips
k = 0.49 usec; j = 0.76; r = 0.80; kr = 0.82; jr = 1.07

ppc64: POWER5 (gr), 1656 MHz (SMT disabled, 1 virtual CPU per physical CPU)
k = 0.77 usec; j = 1.31; r = 1.26; kr = 1.45; jr = 1.9

Creating,Compiling and Loading a Kernel Module

A helloworld.c module

#include

int init_func(void)
{
printk("Hello world 1.\n");
return 0;
}
void cleanup_func(void)
{
printk("Goodbye world 1.\n");
}
module_init(init_func);
module_exit(cleanup_func);

where module_init() and module_exit are macros that label the certain functions as initializing and exiting.

Now create a Makefile

obj-m += helloworld.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

if you forget to give helloworld.o and give it as helloworld.c then you will get an error saying
"target /home/vamshi/helloworld.c doesn't match the target pattern Building modules, stage 2." so be careful.

then run the command "make" for compiling the helloworld module.

Loading a Module
=============

modprobe can be used to load a module. "modprobe" is a program to add or remove modules from the kernel module.but this requires the module to be installed in /lib/modules/ DIRECTORY. Another way is to use "insmod"

insmod -- Installs a loadable kernel module in running linux kernel.

so to load the helloworld module run the command
# insmod helloworld.ko

After loading your module the function registered as the initial function will be run. Try running the dmesg command. You should see a long message ending similar to the following:

# dmesg
...
VFS: Mounted root (reiserfs filesystem) readonly.
Freeing unused kernel memory: 144k freed
eth0: link up
Hello world!

To get the list of currently loaded modules we can use the command "lsmod"

"modinfo" is a command to print out the information about one or more modules.

"rmmod" this command is to unload a module.
#rmmod helloworld.ko

Kernel Module

What is a kernel module?
A kernel module is code that can be dynamically loaded into the kernel during runtime. This makes the Linux kernel extensible so that not all functionality has to be compiled into the kernel during the initial creation. From our experience making our own system call, we know that compiling a kernel is a lengthy process and that was a SMALL kernel.
The first purpose of modules you might think of is probably device drivers that allow the kernel to interact with a new type of hardware. However, modules can add a host of other functionality like filesystems, network protocols, cryptographic libraries, etc.

dmesg

From Wikipedia, the free encyclopedia

dmesg (for "display message") is a command on some Unix-like operating systems that prints the message buffer of the kernel.

When the computer system is initially booted the kernel is loaded into memory. At this stage each device driver present in the kernel probes the system for the existence of relevant hardware. If the hardware is located, a diagnostic message is produced documenting precisely what was found. Other elements within the kernel may also produce similar output reporting both the presence of that particular module, and the values of any parameters adopted. It may be possible to specify boot parameters which control the level of detail in the messages. This process typically happens at a speed where individual messages scroll off the top of the screen before they can be read. Some keyboard keys may pause the screen output. The dmesg command allows these messages to be reviewed in a controlled manner after the system has started.

Even after the system has fully booted, the kernel may occasionally produce further diagnostic messages. Common examples of when this might happen are when I/O devices encounter errors, or USB devices are hot-plugged. dmesg provides a mechanism to review these messages at a later time. When first produced they will be directed to the system console: if the console is in use then these messages may be confused with or quickly overwritten by the output of user programs.

The output of dmesg can amount to several complete screens. For this reason, this output is normally reviewed using standard text-manipulation tools such as more, tail, or grep. The output is often captured in a permanent system logfile via a logging daemon, such as syslog. On Linux systems, similar information is sometimes found in log files in /var/log.

Many commercial operating systems display an animated splash screen during this stage of the boot process, so the user does not see these messages. However, there is frequently a mechanism, such as the Esc key, to disable the splash screen and view the messages. This is an important diagnostic capability if the system fails to boot. There is also usually a method of reviewing these messages subsequent to start up in a manner equivalent to dmesg.


Syslog

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Syslog is a standard for forwarding log messages in an Internet Protocol (IP) computer network.

Syslog is a client/server protocol:[1] a logging application transmit a small (less than 1KB) text message to the syslog receiver. The receiver is commonly called syslogd, syslog daemon or syslog server. Syslog messages may be sent via the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP).[2] The data is sent in cleartext; although not part of the syslog protocol itself, an SSL wrapper may be used to provide for a layer of encryption through SSL/TLS. Syslog uses the port number 514.

Syslog is typically used for computer system management and security auditing. While it has a number of shortcomings, syslog is supported by a wide variety of devices and receivers across multiple platforms. Because of this, syslog can be used to integrate log data from many different types of systems into a central repository.

Syslog is now standardized within the Syslog working group of the IETF.