Thursday, 20 September 2012

Screen Sessions Management

I used this method when I need to login to multiple remote machines using ssh and then become root and then do things interactively simultaneously on them. 

Following steps were performed:
^M => denotes  "Enter" on keyboard. (ctrl-v Enter => ^M)

screen^M  => can also be run as screen -S  <session name>^M
ctrl-a c  => 2 times to create two screen windows in one screen session.

create a file e.g  /tmp/screen_bufferfile  => this file will work as a screen buffer file.
Note : screen default buffer register is called "."  ( dot )

scenario 1 :  Sending Identical commands to everywhere non-interactively.

step 1 = ctrl-a : readbuf /tmp/screen_bufferfile  => this will copy the contents of file in "." register
step 2 = ctrl-a : at "#" paste .   => this command will paste the contents of "." register on every screen window (even to sshed windows also)


scenario 2 : Sending commands interactively.

ctrl-a : bufferfile /tmp/screen_bufferfile  => sets the default buffer file
ctrl-a <        => reads the contents of buffer to "." register
ctrl-a ]         => paste the contents of buffer to current screen window only ( NOT any other )

even the ssh password and sudo password prompts accepts passwords like this.

scenario 3: Sending commands using screen from outside

Create a screen session and create multiple screen in it using ctrl-a c (multiple times)
Get the screen session id (or name) using screen -list

To send unix shell commands(or any input) to ALL windows in a screen session run following 2 commands:
screen -S 3461.ttys000.MacBook-Pro  -X readbuf /tmp/screen_bufferfile
screen -S 3461.ttys000.MacBook-Pro  -X at "#" paste "."
/tmp/screen_bufferfile will contains unix commands or (any input) you want to send to screen windows.

To send unix shell command( or any input) to a particular window run following.
screen -S 3461.ttys000.MacBook-Pro  -X readbuf /tmp/screen_bufferfile
screen -S 3461.ttys000.MacBook-Pro  -p 5 -X paste "." 

readbuf and paste are used in scenes when we have to input some quite a good amount of data. This also relieves from
taking care of quotes and control characters that we have anyways to do when we use "stuff" command. e.g.

Above can also be done by using following:
screen -S 3461.ttys000.MacBook-Pro -p 5 -X stuff "hostname^M"
screen -S 3461.ttys000.MacBook-Pro -X at "#" stuff "hostname^M"

Above we have used actual data on command line itself to send to screen windows. Please note that we have to explicitly used ^M characters to have Enter effect. But this is not the case when we create /tmp/screen_bufferfile.

screen -S javaupdate -X screen   => will spawn screen windows inside screen session (named javaupdate)

=====================================================
To create multiple windows in one screen session non-interactively

screen -d -m -S TEST   => creates a screen session with name TEST and detach it. Does not go into screen session.
screen -S TEST -X screen -t yahoo 03 ssh remotemachine  => creates a screen window inside TEST with name yahoo at window no 3. In window no 3 , there will an ssh session to remotemachine.

Thursday, 14 June 2012

Create Fedora Installer ISO using GRUB

Introduction

This is just method to produce the Fedora Installer DVDs using the Grub boot loader instead of ISOLINUX.

Software Used

Base OS used, on which Fedora-13 installer was created was , Ubuntu 8.04.3 LTS (hardy). Fedora-13 will be used for which installer will be created using GRUB as boot loader.

Steps Performed
Copy the required files
Copy whole DVD contents
mkdir grubdvdrom
mount -o loop /mnt/ISO-IMAGES/Fedora/Fedora-13-i386-DVD.iso /tmp/fedora-13
rsync -avz /tmp/fedora-13/ grubdvdrom/
umount /tmp/fedora-13
Copy grub files from Base OS
mkdir grubdvdrom/boot
cp -r /boot/grub grubdvdrom/boot
cp grubdvdrom/isolinux/{vmlinuz,initrd.img} grubdvdrom/boot
cp /usr/lib/grub/x86_64-pc/stage2_eltorito grubdvdrom/boot/grub

Note: Fedora DVDROM contains some hidden files like .treeinfo, which are must in order to recognize local repos for anaconda installer. If these files are not copied then anaconda will go only to internet for repos. There we used rsync to make sure each file has been copied.Also you have to maintain the tree structure of boot/grub as a whole.

Create menu.lst file
create or modify grubdvdrom/boot/grub/menu.lst file with following contents.
title Fedora-13 Grub ISO Installer
kernel /boot/vmlinuz
initrd /boot/initrd.img
Create ISO
cd grubdvdrom
mkisofs -o Fedora-13.iso -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -J -r -hide-rr-moved -V Fedora