Thursday, February 18, 2010
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=S2) 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/
More Information on Runlevels: http://en.wikipedia.org/wiki/Runlevel
Wednesday, February 17, 2010
Execute a command without saving it in the history
$ 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
Sunday, February 7, 2010
Running Scripts on Shutdown and Startup
=========================
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/
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
