Harry Sukumar's Weblog

Redhat flavor Tweak Auto complete service command

Posted by hsukumar on 23/03/2009

I am a lazy bugger!!!
Type:
complete -W “$(ls /etc/init.d/)” service

* complete : the command complete sets up tab completion
* -W : this option creates a word list for completion
* “$(ls /etc/init.d/)” : out word list is made up of the output of the command ls /etc/init.d/
* service : this then sets up the configured completion for the command service

So next time when you type service command it should automatically auto complete,

hope this helps the Lazy like me :-)

Posted in Uncategorized | Tagged: , , | Leave a Comment »

Mac OS X-change hostname

Posted by hsukumar on 19/03/2009

Change the hostname in Mac OS X [osx]

When I log into the network at my job my Mac’s hostname always turns to:

rice.com.au

I have my local hostname set to:

rice.com

So What I would like to do is set my Mac’s hostname to my local hostname. You can do this all from Terminal in a single line.

Run this command in Terminal:

sudo scutil --set HostName rice.com

 

 

This is also helpful if you’re in Terminal and have a really long hostname at your prompt. If you want to view your current hostname, run this command in Terminal:

hostname

 

This is what it looked like for me:

rice.com

Posted in Uncategorized | Leave a Comment »

Conky on Fedora 10

Posted by hsukumar on 18/03/2009

My Conky file on fedora this is very much a standard file with little tweak

# Conky sample configuration
#
# the list of variables has been removed from this file in favour
# of keeping the documentation more maintainable.
# Check http://conky.sf.net for an up-to-date-list.

# set to yes if you want Conky to be forked in the background
background no

# X font when Xft is disabled, you can pick one with program xfontsel
#font 5×7
#font 6×10
#font 7×13
#font 8×13
#font 9×15
#font *mintsmild.se*
#font -*-*-*-*-*-*-34-*-*-*-*-*-*-*

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
xftfont Bitstream Vera Sans Mono:size=8

# Text alpha when using Xft
xftalpha 0.8

# Print everything to stdout?
# out_to_console no

# MPD host/port
# mpd_host localhost
# mpd_port 6600
# mpd_password tinker_bell

# Print everything to console?
# out_to_console no

# mail spool
mail_spool $MAIL

# Update interval in seconds
update_interval 5.0

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
#own_window yes

# If own_window is yes, you may use type normal, desktop or override
own_window_type normal

# Use pseudo transparency with own_window?
own_window_transparent yes

# If own_window_transparent is set to no, you can set the background colour here
own_window_colour hotpink

# If own_window is yes, these window manager hints may be used
#own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 280 5

# Draw shades?
draw_shades yes

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders yes

# Draw borders around graphs
draw_graph_borders yes

# Stippled borders?
stippled_borders 8

# border margins
border_margin 4

# border width
border_width 1

# Default colors and also border colors
default_color white
default_shade_color black
default_outline_color black

# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right
#alignment none

# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 12
gap_y 12

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2

# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale no

# Add spaces to keep things from moving about?  This only affects certain objects.
use_spacer no

# Allow each port monitor to track at most this many connections (if 0 or not set, default is 256)
#max_port_monitor_connections 256

# Maximum number of special things, e.g. fonts, offsets, aligns, etc.
#max_specials 512

# Maximum size of buffer for user text, i.e. below TEXT line.
#max_user_text 16384

# variable is given either in format $variable or in ${variable}. Latter
# allows characters right after the variable and must be used in network
# stuff because of an argument

# stuff after ‘TEXT’ will be formatted on screen

TEXT
$nodename – $sysname $kernel on $machine
$stippled_hr
${color lightgrey}Uptime:$color $uptime ${color lightgrey}- Load:$color $loadavg
${color lightgrey}CPU Usage:${color #cc2222} $cpu% ${cpubar}
${color red}${cpugraph 0000ff 00ff00}
${color lightgrey}RAM Usage:$color $mem/$memmax – $memperc% ${membar}
${color lightgrey}Swap Usage:$color $swap/$swapmax – $swapperc% ${swapbar}
${color lightgrey}Processes:$color $processes  ${color grey}Running:$color $running_processes
$color$stippled_hr
${color lightgrey}Networking:
Down:${color #8844ee} ${downspeed eth0} k/s${color lightgrey} ${offset 80}Up:${color #22ccff} ${upspeed eth0} k/s
${color #0000ff}${downspeedgraph eth0 32,150 ff0000 0000ff} ${color #22ccff}${upspeedgraph eth0 32,150 0000ff ff0000}
${color lightgrey}File systems:
/ $color${fs_used /}/${fs_size /} ${fs_bar /}
${color #88aadd}MPD: ${alignc}$mpd_artist – $mpd_title
${color #88aadd}$mpd_bar
${color #88aadd}${alignc}$mpd_status
${color}Name              PID     CPU%   MEM%
${color #ddaa00} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color lightgrey} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color lightgrey} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color lightgrey} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${color}Mem usage
${color #ddaa00} ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}
${color lightgrey} ${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}
${color lightgrey} ${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}

${tail /var/log/Xorg.0.log 3 30}

${color red}${tail /var/log/messages 5}

$stippled_hr
${color #ddaa00}Port(s)${alignr}#Connections
$color Inbound: ${tcp_portmon 1 32767 count}  Outbound: ${tcp_portmon 32768 61000 count}${alignr}ALL: ${tcp_portmon 1 65535 count}
${color #ddaa00}Inbound Connection ${alignr} Local Service/Port$color
${tcp_portmon 1 32767 rhost 0} ${alignr} ${tcp_portmon 1 32767 lservice 0}
${tcp_portmon 1 32767 rhost 1} ${alignr} ${tcp_portmon 1 32767 lservice 1}
${tcp_portmon 1 32767 rhost 2} ${alignr} ${tcp_portmon 1 32767 lservice 2}
${tcp_portmon 1 32767 rhost 3} ${alignr} ${tcp_portmon 1 32767 lservice 3}
${tcp_portmon 1 32767 rhost 4} ${alignr} ${tcp_portmon 1 32767 lservice 4}
${tcp_portmon 1 32767 rhost 5} ${alignr} ${tcp_portmon 1 32767 lservice 5}
${color #ddaa00}Outbound Connection ${alignr} Remote Service/Port$color
${tcp_portmon 32768 61000 rhost 0} ${alignr} ${tcp_portmon 32768 61000 rservice 0}
${tcp_portmon 32768 61000 rhost 1} ${alignr} ${tcp_portmon 32768 61000 rservice 1}
${tcp_portmon 32768 61000 rhost 2} ${alignr} ${tcp_portmon 32768 61000 rservice 2}
${tcp_portmon 32768 61000 rhost 3} ${alignr} ${tcp_portmon 32768 61000 rservice 3}
${tcp_portmon 32768 61000 rhost 4} ${alignr} ${tcp_portmon 32768 61000 rservice 4}
${tcp_portmon 32768 61000 rhost 5} ${alignr} ${tcp_portmon 32768 61000 rservice 5}

Posted in CentOS, Debian, General Linux, Redhat MIX, Ubuntu | Leave a Comment »

compizconfig-settings manager

Posted by hsukumar on 14/03/2009

To Configure compiz on redhat machines please install ccsm
# yum install ccsm

This is the fronend tool to manupulate the graphics

Posted in Uncategorized | Tagged: , | Leave a Comment »

Permission & Umask on files

Posted by hsukumar on 12/03/2009

The default permission for files is 666 and directory is 777. umask is used to withhold permission. Default root’s umask is 022. without a umask in effect, only file created will have 666 permission and directory will have 777. this means that anyone on the system will have read and write access to any file. A umask of 002 will result in file created with 664 permission and directory with permission 775.

Default umask on Red hat enterprise linux is 002. to change

#umask 022

umask is typically set by script run at login time. The next time you lig in umask will be set bask to your default unless you add command to one of your startup files such as .bashrc.

User Mask

Default value for root = 0022

Default value for users = 0002

When we create any new file. The default value will be 666. in this case Umask means 666-002 = 664 for normal user and for the root the default value will be 666-022=644

The default value for a directory is 777. in this case umask means that whenever we create new directory, the default valkue for normal user 777-002 = 775 and for root, the default value 777-022 = 755

Posted in Uncategorized | Leave a Comment »

Increase swap size

Posted by hsukumar on 12/03/2009

There are possibilities that any time we can increase the size of RAM, at that time we need to increase the size of swap partition as per the increased size of the RAM.

There are two method of doing so

a. creating partition

b. Creating file

  1. Creating Partition:

i. We have to create one partition of size say 200MB and change its type to 82 (swap type) . save and exit and then run the command “partprobe”

ii. Format the partition say /dev/hda9

#mkswap /dev/hda9

iii. Make the swap partition active

#swapon /dev/hda9

iv. to check the entry of swap partition

# cat /proc/swaps

If we want to make the permanent entry in fstab then

#vi /etc/fstab

/dev/hda9 swap swap defaults 0 0

  1. Creating file

i. first make an empty file

#touch /swp

ii. Now we customize the size of the swap

# dd if=/dev/zero of=/swp bs=1M count=200

iii. Format the newly created swap file

#mkswap /swp

iv. Active the swap file

#swapon /swp

To check the entry of swap file

#cat /proc/swaps

If we want that automatically this swap file activate , we need to make the entry in /etc/ec.local

# vi /etc/rc.local

Make the following entry

Swapon /swp

Save and exit

Posted in CentOS, Debian, General Linux, Redhat MIX, Ubuntu | Leave a Comment »

ethtool- Check Network Connection

Posted by hsukumar on 12/03/2009

[root@Fedora01 ~]# ethtool eth1
Settings for eth1:
Current message level: 0×00000007 (7)
Link detected: yes

For more information please refer to man pages :)

Posted in CentOS, Redhat MIX, Ubuntu | Leave a Comment »

Network Troubleshooting Linux

Posted by hsukumar on 12/03/2009

Sources of Network Slowness

  • NIC duplex and speed incompatibilities
  • Network congestion
  • Poor routing
  • Bad cabling
  • Electrical interference
  • An overloaded server at the remote end of the connection
  • Misconfigured DNS

TEST YOUR NIC

It is always a good practice in troubleshooting to be versed in monitoring the status of your NIC card from the command line. The following sections introduce a few commands that will be useful.

The ifconfig command without any arguments gives you all the active interfaces on your system. Interfaces will not appear if they are shut down:

[root@bigboy tmp]# ifconfig

Note: Interfaces will appear if they are activated, but have no link.

DHCP Considerations

DHCP clients automatically give their NICs and IP address starting with 169.254.x.x until they can make contact with their DHCP server. When contact is made they reconfigure their IP addresses to the values provided by the DHC server. An interface with a 169.254.x.x address signifies a failure to communicate with the DHCP server. Check your cabling, routing and DHCP server configuration to rectify such a problem.

Testing Link Status from the Command Line

Link Status Output from ethtool

[root@test.com tmp]# ethtool eth0

Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@test.com tmp]#

Testing Web sites with the curl

Using curl

The curl utility acts like a text based Web browser in which you can select to see either the header or complete body of a Web page’s HTML code displayed on your screen.

A good start is to use the curl command with the -I flag to view just the Web page’s header and HTTP status code. By not using the -I command you will see all the Web page’s HTML code displayed on the screen. Either method can provide a good idea of your server’s performance.

[root@ bigboy tmp]# curl -I www.testing.com
HTTP/1.1 200 OK
Date: Tue, 19 Oct 2004 05:11:22 GMT
Server: Apache/2.0.51 (Fedora)
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: text/html; charset=UTF-8
[root@test.com tmp]#

Using netcat to Test Network Bandwidth

Most Linux distributions contain the netcat or nc packages which can be used to create a TCP socket over which you can transfer data. The syntax can also vary between distributions so you should refer to your system’s man pages if you have any questions.

The netcat server can be easily created with the -l switch that signifies the program should listen, and not talk. The desired TCP port then follows. In this case the server is listening on TCP port 7777.

[root@smallfry tmp]# nc -l 7777

The netcat client only needs to specify the server’s IP address followed by server’s the TCP listener port.

[root@bigboy ~]# nc 192.168.2.50 7777

Any text typed to the console screen of the client;

[root@bigboy ~]# nc 192.168.2.50 7777 This is a test of the NetCat program! [root@bigboy ~]#

will also be visible on the server’s console.

[root@smallfry tmp]# nc -l 7777 This is a test of the NetCat program! [root@smallfry tmp]#

If you want to transfer a file, you only need to use some simple command line redirection. In this case, the server will output all data it receives on port 7777 to a file called FC-6-i386-disc1.iso, and the client pipes the output of the cat command to the netcat client that points to our server.

[root@smallfry tmp]# nc -l 7777 > FC-6-i386-disc1.iso [root@bigboy ~]# cat /tmp/FC-6-i386-disc1.iso | nc 192.168.2.50 7777

All Linux systems have a black hole file named /dev/null which automatically discards any data written to it. If you want to test file transfers without filling your disk storage, or having the server’s disk I/O be a bottleneck, then use this as your output file instead.

[root@smallfry tmp]# nc -l 7777 > /dev/null

All Linux systems also have a have a continuous random data source located at /dev/random. Instead of using a file in your tests, you can use this instead for a data stream or infinite duration.

[root@bigboy ~]# cat /dev/random | nc 192.168.2.50 7777


Posted in Uncategorized | Leave a Comment »

Sudo

Posted by hsukumar on 10/03/2009

sudo is a package which will allow priveleged users to run commands as other users. This is sort of like assigning users to different groups to give them special permissions to files. However, this can allow users acccess to specific commands on specific machines, making it a more effective and more organized way of giving special priveleges to users.

First, you’ll have to get the sudo package.

# yum install sudo -y

Configuring SUDOers

Now that sudo has been installed, you should find a file called /etc/sudoers.

Before you start editing this file, you need to use a program called visudo, included in the sudo package. This edits provides security checks, parses for errors, and protects against multiple edits of the file.

Visudo takes the editor which is stored in the environment variable VISUAL so to pick an editor, for instance pico, while running a bash shell, enter the command:

export VISUAL="nano"

Now, simply type: visudo and it should open /etc/sudoers in that editor.

In /etc/sudoers, you should see something like this:

NOTE: You may see other things, this is what is in Debian’s install. There are many options which I do not go over here, for instance how to override defaults. This guide is meant to be a source for creating a basic setup of sudo. You can find anything I did not include in “man sudoers” and “man sudo”

#Host alias specification #User alias specification #Cmnd alias specification #User privilege specification root ALL=(ALL) ALL

Here’s a sample file, which is not real, but as I walk you through it, you should be able to understand how to setup this file.

Aliases are ways of referring to information by an (usually)easier name. They are sort of like the short hand way of writing something. In our case, aliases can point to 1 piece of information, or can point to groups of information as you’ll see below.

Host alias specification

This section makes aliases for hosts. The syntax is:

Host_Alias ALIASFORHOSTNAMES = hostname1, hostname2, etc…

These will allow you to make an alias for sets of hostnames (Or even a single one.)

The two lines below make an alias called “DJNET,” which refers to hostnames, djbox1 and djbox2 and an alias called “LINUXHELP,” which will refer to hostnames lingroup1,lingroup2.

These hostnames should be referenced in /etc/hosts and you for the hostnames you may use IP addresses, hostnames in /etc/hosts, or other hostnames which may not be found in /etc/hosts.

Host_Alias DJNET = djbox1, djbox2 Host_Alias LINUXHELP = lingroup1,lingroup2

User alias specification

This section, like the Host Alias section basically is a way of grouping users.

The syntax is:

User_Alias USERGROUPNAMEALIAS = user1, user2, etc…

The below lines make 3 groups, ADMINS, PARTTIME, and LINUXGROUP, each containing different members.

User_Alias ADMINS = joe, bill, jake User_Alias PARTTIME = jim, jeff, mike User_Alias LINUXGROUP = lyte, SirPlaya

Cmnd alias specification

This section is a way of grouping commands together. The syntax is:

Cmnd_Alias COMMANDALIASNAME = command1,command2,etc…

If you’d like to specify arguments, you can use [] and wildcards to make commands. For instance, one of the below aliases, USERS includes has /usr/sbin/adduser [A-z]*, which means that they can run /usr/sbin/adduser and must have an argument of a 1 or more letters.

Cmnd_Alias BROWSE = /bin/ls, /bin/cd, /bin/cat Cmnd_Alias KILL = /bin/kill Cmnd_Alias USERS = /usr/sbin/adduser [A-z]*,/usr/sbin/userdel -r [A-z]*

User privilege specification

This is the User privilege section. This is where you give out the special priveleges to users, or user aliases using the aliases we have created above.

The syntax is:

USER HOST=COMMANDS Where USER can be either a user name or user alias, as well as HOST and COMMANDS.

The below line allows root access to everything… this shouldn’t be a problem as root can do whatever he/she wants anyway.

root ALL=(ALL) ALL

This next line will allow the users specified in the ADMINS alias (joe, bill, and jake) and give them access to everything as well.

ADMINS ALL=ALL

This next line will show you another interesting feature of sudo. This allows the users in the PARTTIME alias (jim,jeff,mike) to do all of the commands listed in USERS,KILL,and BROWSE aliases on all servers. In addition to that, they may run /usr/bin/passwd followed by a 1 letter word or more(username of password to change) but the last option says that they CANNOT change root’s password. ! is used to represent the word “NOT”

PARTTIME ALL=USERS,KILL,BROWSE,/usr/bin/passwd [A-z]*, !/usr/bin/passwd root

This next line allows user “djg” access to everything on the hosts listed in the alias DJNET(djbox1 and djbox2). It IS my network after all. :)

djg DJNET=ALL

Finally, this last line allows the users listed in the alias LINUXGROUP (lyte and SirPlaya) access to ALL commands as user “www” and to all of the commands listed in the aliases KILL,USERS, and BROWSE on the servers listed in the alias LINUXHELP(lingroup1 and lingroup2).

To specify that commands can be run as a user other than root, put the username in () in front of the commands. If you need to use root after that, you will have to specify it as seen below.

LINUXGROUP LINUXHELP=(www) ALL (root) KILL,USERS,BROWSE

Now that /etc/sudoers is configured properly, save it and exit visudo. If there are any errors, it should tell you.

USING SUDO

To list what you are allowed to do with sudo:

djg@localhost:~ $ sudo -l Password: (Enter your password here) User djg may run the following commands on this host:

(Here will be what you are allowed to do. It will follow the form of /etc/sudoers)

To use a privelege:

djg@localhost:~ sudo -u usertoruncommandas commandhere

Password: (Enter your password here)

(The command will then execute if everything is ok)

Flag -u will default to user root so if you’re running a command as root, it’s not necessary, simply use: sudo commandhere.

In some cases, it may not prompt you for a password. By default, sudo will allow you to go 5 minutes without entering a sudo command before it asks you for a password again. Again, as I said before, I don’t go over how to change that in this guide. Everything you’ll need is in the man pages. At some point, I may add that section to this guide.

Now you should have a fully working sudo package and now users can have special priveleges.


Posted in CentOS, Debian, General Linux, Redhat MIX, Ubuntu | Leave a Comment »

How to Xen on Redhat based Machines

Posted by hsukumar on 05/03/2009

Need root shell access

Doing the work

  1. Check if the required Xen packages are already installed:
    # rpm -q xen kernel-xen virt-manager
  2. If it tells you if the packages are installed including the version number, proceed to the next step. Otherwise, install them by:
    # yum install xen kernel-xen virt-manager
  3. After installation, the service should be configured to start automatically.
    # chkconfig xend on or chkconfig --levles 345  xend on
  4. Restart the computer (it should boot to the new Xen™ kernel). To check:
    # uname -a
  5. To start the Xen™ daemon.
    # /sbin/service xend start
  6. Test the set-up by using virt-manager.
    # virt-manager

You should see the virtual machines currently on your host.

Posted in Uncategorized | Leave a Comment »