Adding script to run at startup or shutdown in Linux
March 10, 2009 at 3:45 PM | Posted in Linux | 1 Comment1. Write a script and put it into /etc/init.d/ directory. Your script must have start or stop options or both, depends on when you want to run your script. start is called at reboot or system startup and stop is called at shutdown.
2. Add the executable permission to your script. Let say your script name is test
# chmod +x test
3. Create symbolic link in /etc/rc#.d where # is runlevel number. To know more about run level check /etc/initab or check init man page (type man init).
For example if you want to run your script at system startup, create a symbolic link in /etc/rc3.d:
- # cd /etc/rc3.d/
# ln -s ../init.d/scriptname S##scriptname where ## is order of executing script or you can say starting number. Use some 50 or 60. You should choose this number according to the needs of your application: if you try to make the application start too early, all disks may not be mounted yet, network adapters might not be initialized or some system services might not be started yet.
the rc script will start all scripts with a capital S in numerical order.
The shutdown portion is similar. Go to the run level that you want to shutdown at:
- cd /etc/rc0.d/
- ln -s ../init.d/scriptname K##scriptname where where ## is order of executing script or you can say starting number. Use some 50 or 60.
the rc script will shutdown all scripts with a capital K in numerical order.
sample script
#!/bin/sh
# Copy at startup and remove at shutdown
#
start() {
cp /etc/test /var/tmp/
}
stop() {
rm -rf /var/tmp/*
}
case “$1″ in
start)
start
;;
stop)
stop
;;*)
echo $”Usage: $0 {start|stop}”
RETVAL=1
esac
exit 0
4) Your process is done. Now you can test your script.
Few commands for runlevel and init
1) To switch to particular run level use init
$ telinit 6
2) chkconfig is a tool that helps in creating/deleting/changing the symbolic links. It requires that you put two specially-formed comment lines in your application startup/shutdown script:
#chkconfig –list to check the current startup settings
# chkconfig: 345 80 20
The numbers on the chkconfig line:
- The first number (345) is a list of runlevels you’ll want your application. So it will run at runlevel 3, and 5.
- 80 is the “starting position” number, meaning that this application will be started rather late in the boot process.
- 20 is the “shutdown order” number. Unless your application has special requirements, it is recommended that the sum of startup and shutdown order numbers for each application should be 100.
When you have added the two “magic” comment lines to your startup/shutdown script, just place the script to /etc/init.d and run:
chkconfig –add
If you need to temporarily block the system from starting/stopping the application automatically, you can use:
chkconfig off
To restore the auto-start function, use:
chkconfig on
Install packages on Linux…
March 10, 2009 at 12:12 PM | Posted in Linux | Leave a commentMake and install program from source (tar.gz)
- Put the packed file (tar.gz) in the directory you want it to be installed under.
- Open the compressed tar ball “tar zxvf <packagename>.tar.gz” . It will create a directory like “packagename-2.3.4″ and place the extracted information here.
- Go into the created subdirectory and type “./configure”.
- Type “make all”
- Type “make install”
RPM (Red Hat Package Manger) – Most common method of distribution of software for Linux. rpm command provides for installation, removal, upgrade, verification and other management of RPM packages.
1) Install new package – use rpm -i or rpm ihv for verbose information
#rpm -ihv gcc-2.96-113.i386.rpm
2) To upgrade a existing package to newer version -
#rpm -U binutils-2.11.93.0.2-11.i386.rpm
3) To remove a package
#rpm -e binutils-2.11.93.0.2-11.i386.rpm
Frequently used option in uninstall
–nodeps – skips dependency checking
–test – Run through all the motion except for actually installing things. Useful to verify that a package can be uninstalled correctly.
4) Query about package (-q)
-a display a list of all the packages installed on the system – rpm -qa
-f filename – display a package that contain file name
-R list packages on which this package depends
To know about any installed package
#rpm -ql <package_name> or rpm -qa|grep <package_name>
To list the files contained in the package
#rpm -qlp binutil.i386.rpm
Setting Environment variable in Linux
March 5, 2009 at 11:10 AM | Posted in Linux | 2 CommentsThe following setting is for FC8 Linux. The file name or path may change for different flavor of Linux
For system wide effect , edit /etc/bashrc file and for particular user edit file home/<username>/.bash_profile and add your environment variable. For example, adding JAVA_HOME variable
#export JAVA_HOME=/usr/bin
Then save the file and run it using source command.
#source /etc/bashrc or source /home//.bash_profile
You can test it by
echo $<your_variable_name>
Install Internet Explorer 6 on Linux
February 18, 2009 at 6:19 PM | Posted in Linux | Leave a commentOpen a terminal. Log in as root to install wine and cabextract:
yum -y install wine*
yum -y install cabextract
Logout and install IEs 4 Linux with your normal user account:
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux
GNU screen tutorial
February 12, 2009 at 2:35 AM | Posted in Linux | 1 CommentScreen is best described as a terminal multiplexer utility. It allows you to have multiple virtual terminal instances over a single terminal connection.
Creating a new session
To start screen type screen on command prompt.
$ screen
or you can give screen name also
$screen -S <screen name>
Creating a new window
Type Ctrl+a c.
Every new created screen window is identified by an unique number. The first window (the one you’re actually using) is numbered as 0, while future windows will be labeled as 1, 2, 3 etc.
Switching between windows
a) Use Ctrl-a n and Ctrl-a p to switch to the next or previous window in the list and Ctrl-a space, to toggle through the shells.
b) Use Ctrl-a N, where N is a number from 0 to 9, to switch to the corresponding window.
c) Use Ctrl-a ” to get a full-screen list of windows. You can navigate this list with the arrow keys (or vi-style, with j and k), and pick a window to activate by pressing Enter when it’s highlighted. C-a w will give you a small, non-interactive list of windows.
Renaming Windows
Type Ctrl-a A, it will be prompted for a new window name.
Detaching and reattaching
Type Ctrl-a d for detach
$screen -r to re-attach or resume session
Sharing the session between multiple user
We’ll use a very simple scenario for this one. Let’s say Jake wants to share access to a screen session with Bob. Jake & Bob both have accounts on the system.
1. In order to enable multiuser mode the screen binary must be setuid for root.
# chmod u+s /usr/bin/screen
2. Jake starts a screen session.
jake$ screen -S shared
3. Jake must enable multiuser mode.
CTRL+a : multiuser on
This could be added to ~/.screenrc to have it enabled for all sessions, but case-by-case is probably safer.
4. Jake must add Bob to the access control list for his session.
CTRL+a : acladd bob
5. Bob lists the screen sessions that Jake has available.
bob$ screen -list jake/
There are several screens on:
1951.pts-1.testbox (Private)
1994.shared (Multi, attached)
2 Sockets in /tmp/screens/S-jake.
This shows us that Jake has 2 sessions. The second session named “shared” is a multiuser session & Jake already has it attached.
6. Bob attaches Jake’s multiuser session.
bob$ screen -x jake/shared
Bob could also connect using the PID.
7. Jake can check to see if Bob is connected to his session.
CTRL+a *
This brings up a list of users in a screen session.
term-type size user interface window
———- ——- ———- —————– ———-
xterm 80×24 bob@/dev/pts/11 0(email) rwx
linux 80×24 jake@/dev/tty1 0(email) rwx
[Press Space to refresh; Return to end.]
8. Jake can boot Bob from his screen session.
CTRL+a : acldel bob
Bob is immediately disconnected and sees…
[remote detached]
bob$
Monitoring
Say you’ve got a whole bunch of windows open. One of those windows is idling in a very inactive IRC channel. Since not much goes on in there, you don’t keep that window active but you would like to know when something is said. screen lets you monitor any window for activity by first switching to the window, and then hitting ^A M. When activity in that window occurs, screen will display a message at the bottom.
On the other hand, say one of your windows is a compile of X. There’s lots and lots of activity and you’d like to know when the build is finished. You can monitor for 30 seconds of inactivity by switching to the window and hitting ^A _. When the window goes silent, screen will display a message at the bottom.
These monitoring commands are toggles, so you can turn them off by switching to any monitored window and issuing the command again.
Copy and Paste
Here’s a feature that can be useful if you’re stuck in console mode & don’t have a mouse available. screen has its own built in buffer for copying & pasting text into the same or other windows.
1. Enter copy mode by pressing CTRL+a [
The status bar will read "Copy mode" with column & line information.
2. Move the cursor to the beginning of the block you wish to copy using standard vi keys or the arrow keys.
3.Press the ENTER key.
The status bar will read "First mark set" with column & line information.
4. Move the cursor to the end of the block you wish to copy using standard vi keys or the arrow keys.
5. Press the ENTER key.
The status bar will read "Copied X characters into buffer".
6. Paste the copied text with CTRL+a ]
Record linux shell session output
February 4, 2009 at 12:50 PM | Posted in Linux | 2 Comments1) send command to start recording and saving the output into output.txt
#script output.txt
2) now execute any command, it will save it to the file output.txt. e.g.
#ls
3) exit to stop recording the session.
#exit
Now you can see the session output in any editor or cat command
#cat output.txt
How to format pen drive in Linux
January 13, 2009 at 2:41 PM | Posted in Linux | Leave a commentAbout device name in Linux : – Normally, Linux recognize first disk as sda, next is sdb, then sdc and so on. So if your system has one hard disk, it is sda and next added media (can be hard disk or USB or any other storage device) will be sdb. Their partition name will be sda1, sda2, sdb1 sdb2 etc.
Let us assume that /dev/sdb1 is your partition name for USB pen. Follow the steps below to format the pen drive.
1) Unmounting the device, using. To run the command you must be root user.
unmount /dev/sdb1
2) Use the mkfs.vfat command to format to FAT32 filesystem.
mkfs.vfat /dev/sdb1
3) That’s it!.Remove and insert again and start using it.
Imp Linux Comamnd
December 2, 2008 at 7:06 AM | Posted in Linux | Leave a comment1) stat – display file or filesystem status
2 zip -r
ex. zip -r test.zip test
3) ntsysv – simple interface for configuring runlevels
4) chkconfig – updates and queries runlevel information for system services
5) last – last, lastb – show listing of last logged in users
6) init, telinit – process control initialization
7) alias – It will list your current aliases. You can use unalias to remove the alias.
Few keyboard shortcuts
Ctrl+L = Clears terminal output. similar to clear command
http://web2linux.blogspot.com/2007/09/top-25-linux-commands.html
Creating a central syslog server
December 2, 2008 at 7:01 AM | Posted in Linux | Leave a commentConfigure syslog server and client on Linux(FC4 and FC8) box
Changes needed on the syslog client (machine that will accept syslog messages)
1. vi /etc/sysconfig/syslog
2. Change:
SYSLOGD_OPTIONS=”-m 0″
To:
SYSLOGD_OPTIONS=”-m 0 -r -x”
This change to the syslog daemon enables logging from remote machines and disables DNS lookups on incoming syslog messages.
Changes needed on the syslog server (machine that send syslog messages)
1. vi /etc/syslog.conf
Add the following lines:
# Send a copy to remote loghost
*.info @loghost
auth.* @loghost
Note: make sure that you do not have extra whitespace in the Solaris syslog.conf file. Separate the facility and severity from the location with either a single space or with tabs.
2. vi /etc/hosts
Remove any reference to “loghost.” By default, Solaris will configure each host to be its own loghost.
3. Send the syslogd process a SIGHUP signal (kill -HUP pid_of_syslogd).
If you are using DNS, you will want to add a DNS A record for your “loghost” server. Since it may already have an entry in DNS, you may wish to use a DNS CNAME record.
If you are using NIS in your environment, you may want to add “loghost” to your NIS hosts map.
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.