Sunday, May 26, 2013

RHEL 5 parted command step by step.

To test this we used RHEL 5 n vmware.
1. Add a new SCSI type hard disk
2. vm machine will save it and process for you
3. after may be one minute run fdisk -l as root and see if you can see the disk you created

Disk /dev/sdb: 1073 MB, 1073741824 bytes
81 heads, 26 sectors/track, 995 cylinders
Units = cylinders of 2106 * 512 = 1078272 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         186      195312+  83  Linux
Partition 1 has different physical/logical endings:
     phys=(24, 80, 26) logical=(185, 39, 2)

Now run the command:

[root@smtreeprd04 ~]# parted /dev/sdb
GNU Parted 1.8.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
Got following error:
(parted) mkpart
Error: Unable to open /dev/sdb - unrecognised disk label.

Lets label the disk:

(parted) mklabel msdos
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]?
Start? 1 200
(parted) p

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
 1      0.51kB  200MB  200MB  primary

Now exit the parted utility and format the partition with mkfs

[root@smtreeprd04 ~]# mke2fs /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
48960 inodes, 195312 blocks
9765 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
24 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

create a directory for mount  point

mkdir /sdb1

[root@smtreeprd04 ~]# mount /dev/sdb1 /sdb1/

[root@smtreeprd04 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             5.7G  2.3G  3.2G  43% /
/dev/sda1              99M  9.9M   84M  11% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/sda7             965M   18M  898M   2% /home
/dev/sda6             1.5G   35M  1.4G   3% /opt
/dev/sda2             9.5G  5.4G  3.7G  60% /var
/dev/sdb1             185M  1.6M  174M   1% /sdb1

Thanks.



Friday, May 24, 2013

one liner for file system size in GB sorted.

This command will generate the output to check the file systems in GB larger on the top.
cd to the directory you want this command to run on.

 du -sh * | egrep '([0-9][G])' | sed 's/[0-9][K,M]//g' | sort -rn

I ran this and found that, this works but with one glitch. It is going to return the file names too with size if the file names have "G" exactly in the name. To overcome this run following for loop in the directory which sub-directories file size you want to count.

for i in `ls -l  | grep "^d" | awk '{print  $9}'`  ; do du -sh $i ; done | egrep '([0-9][G])' | sort -rn

Thanks

Tuesday, May 21, 2013

How to connect vsftpd via browser or Windows Explorer on Centos 6.4.

Here are the steps...

Install the vsftpd-2.2.2-11.el6_3.1.x86_64 rpm. This will create the /var/ftp/pub directory
upload your stuff here.

Make changes to the /etc/vsftpd/vsftpd.conf file as per your requirement. I added a few as follows:

banner_file=/etc/vsftpd/issue
local_enable=YES
xferlog_std_format=NO etc...


Add entry in the iptables:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

restart the vsftpd daemon:

[root@smacentos6 mnt]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]


Open the windows explorer or browser - It did not work.

Solution: load the following modules:

[root@smartcentos6 ~]# modprobe ip_nat_ftp
[root@smartcentos6 ~]# modprobe  ip_conntrack_ftp

restart the vsftpd daemon:

[root@smacentos6 mnt]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

Again restart the
see the screenshot:



Thanks,
-Raj





Issue: Changing the system time zone after installation in Red Hat 5.8



Checked the date with date command.  showing the following output.
[support@smarthost ~]$ date
Wed Feb 13 13:42:57 PST 2013
Checked the /etc/localtime file it was not soft linked to the required timezone.
Hence created a soft link as follows to the /usr/share/zoneinfo/PST8PDT
[root@smarthost ~]# ln -s /usr/share/zoneinfo/PST8PDT /etc/localtime
[root@smarthost ~]# date
Wed Feb 13 21:52:07 UTC 2013
Still showing same old time. Thought about visiting the hwclock command
And the glitch is there, see below:
[root@smarthost ~]# hwclock   --show
Wed 13 Feb 2013 09:49:16 PM UTC -0.411498 seconds
Checked help on the command
[root@smarthost]# hwclock --help
hwclock - query and set the hardware clock (RTC)

Usage: hwclock [function] [options...]
Functions:
  -h | --help         show this help
  -r | --show         read hardware clock and print result
       --set          set the rtc to the time given with --date
  -s | --hctosys      set the system time from the hardware clock
  -w | --systohc      set the hardware clock to the current system time
       --systz        set the system time based on the current timezone
       --adjust       adjust the rtc to account for systematic drift since
                      the clock was last set or adjusted
       --getepoch     print out the kernel's hardware clock epoch value
       --setepoch     set the kernel's hardware clock epoch value to the
                      value given with --epoch
  -v | --version      print out the version of hwclock to stdout

Options:
  -u | --utc          the hardware clock is kept in UTC
       --localtime    the hardware clock is kept in local time
  -f | --rtc=path     special /dev/... file to use instead of default
       --directisa    access the ISA bus directly instead of /dev/rtc
       --badyear      ignore rtc's year because the bios is broken
       --date         specifies the time to which to set the hardware clock
       --epoch=year   specifies the year which is the beginning of the
                      hardware clock's epoch value
       --noadjfile    do not access /etc/adjtime. Requires the use of
                      either --utc or --localtime
       --adjfile=path specifies the path to the adjust file (default is
                      /etc/adjtime)
       --test         do everything except actually updating the hardware
                      clock or anything else
  -D | --debug        debug mode

Ran the following command and magic worked!
[root@smarthost ~]# hwclock -s
[root@smarthost ~]# date
Tue May 21 14:38:32 PDT 2013
chkconfig --level 35 ntpd on
[root@smarthost ~]# date
Tue May 21 14:47:06 PDT 2013

Friday, May 17, 2013

sosreport in red hat enterprise linux 6.

I came across this feature of RHEL-6 only when one of the box would reboot after certain interval of time.
It is real easy - What you need is the Redhat case number you are working on. and simply run the command sosreport as root.

[root@RHEL-6 app]# sosreport


sosreport (version 2.2)

This utility will collect some detailed information about the

hardware and setup of your Red Hat Enterprise Linux system.

The information is collected and an archive is packaged under

/tmp, which you can send to a support representative.

Red Hat Enterprise Linux will use this information for diagnostic purposes ONLY

and it will be considered confidential information.


This process may take a while to complete.

No changes will be made to your system.

Press ENTER to continue, or CTRL-C to quit.

Please enter your first initial and last name [RHEL-6]: rs

Please enter the case number that you are generating this report for [None]: 6565

Running plugins. Please wait ...

Completed [51/51] ...

Creating compressed archive...

Your sosreport has been generated and saved in:

/tmp/sosreport-rs.6565-20130517101218-255f.tar.xz

The md5sum is: fc67174ab37703f92999ee50a4fa255f

Please send this file to your support representative.

You have new mail in /var/spool/mail/root

Thanks!

Tuesday, May 7, 2013

Simple tip for cron and at :-)

May be funny but as today's enterprise environment is using more and more automated job schedulers and messaging solutions, cron and at got somewhat sidelined. And all of a sudden I had to schedule a cron job and laugh ha ha - I configured it but just was not seeing the output it took awhile to recollect from the memory - that the output is send by default to the user email.

So if you are testing the cronjob as user rajusa10. run the command mail and check the status of the cron or at job output. That is the default behaviour. You can always modify that redirecting the output via sendmail on SMTP port to the intended recipient.

in the below example:


[rajusa10@rhel-6 ~]$ crontab -l

* * * * * echo "Hi this is a test message"

I am broadcasting the message every minute. Lets test it by command mail





[rajusa10@rhel-6 ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/rajusa10": 1 message 1 new
>N  1 Cron Daemon           Tue May  7 13:24  21/770   "Cron echo "Hi this is a test message""

Remove the cron job now or it will keep repeating the message every minute.

Lets test at command : which is used for one time job execution. Once you have entered the command enter and press Ctrl-D that will save the at job for execution depending on the time selected.

[rajusa10@rhel-6 ~]$ at 1:26pm
at> echo "Hello Raj"
at>
job 6 at 2013-05-07 13:26

The output:

Message  3:
From rajusa10@rhel-6.localdomain  Tue May  7 13:26:01 2013
Return-Path:
X-Original-To: rajusa10
Delivered-To: rajusa10@rhel-6.localdomain
Subject: Output from your job        6
To: rajusa10@rhel-6.localdomain
Date: Tue,  7 May 2013 13:26:01 -0700 (PDT)
From: rajusa10@rhel-6.localdomain (Raj)
Status: R

Hello Raj

Some important tips:

1. no need to restart the crond daemon to apply the job updates. cron checks that for every minute by default.
2. No need to mention username while defining with crontab tool