Tuesday, April 15, 2014

Using while to run a command number of times + UNIX

Hi Friends,

We can use while to run a command multiple times with a time difference of n seconds.

[root@abc /]# while true
> do sleep 10
> df -h
> done
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   19G   28G  41% /
tmpfs                 935M  408K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  5.5G   42G  12% /home

===========


the output of df command is coming after every ten seconds. these can be used when monitoring the size of file system while reducing it using find or rm.

Love Sharing
Amit Chopra

Thursday, April 3, 2014

How to read wtmp, btmp and utmp files + Linux

Hi Friends,

Learning Linux is now more exciting to me, I stay very happy when i learn any new thing about UNIX systems.sharing the same with you my friends, please add more in this if find me correct or incorrect so that we all can share better with everyone and understand more about UNIX system and working on it.

Reading files with cat, vi and more depends only upon the type of file which we want to check or read or see. So it is best to check the type of file with "file --name of the file-- ".

#file /var/log/wtmp
wtmp: data
#

so to read it we can try with Command "STRINGS" i.e.

#strings wtmp

but this output doesn't show the output in human readable form. so we can use "last -f" command. like below :- last -f /var/log/wtmp

we can also redirect this output to /tmp or desired location. and can then read this file properly.
-----
-----

wtmp file carries login details, reboot or system boot details with timings, terminals detail, with format of Day, Date, Time, System Crash/ Went Down/Made reboot.

utmp , wtmp carries login records and it also depends on type of programs using utmp logging as not all programs uses utmp logging.

utmp can be found in

/var/log/utmp
/var/run/utmp

btmp file carries login details, attaching the output in text file so that it can be read.

again

last -f "/var/log/btmp" ---- will give output in detail and can be redirected to any desired path.

attaching the o/p below :-

[root@localhost log]# last -f btmp
(unknown tty1         :0               Fri Mar 28 13:29    gone - no logout
ROOTEST1 tty7         :0               Wed Mar 26 20:28    gone - no logout
ROOTTEST tty7         :0               Wed Mar 26 20:25 - 20:28  (00:03)   
test123  tty7         :0               Wed Mar 26 20:15 - 20:25  (00:10)   
harish   tty1         :0               Tue Mar 11 06:48 - 13:29 (17+06:41) 
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29    gone - no logout
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   
root     ssh:notty    175.125.29.35    Sun Mar  2 05:29 - 05:29  (00:00)   

-============================================

btmp begins Sun Mar  2 02:09:17 2014
[root@localhost log]# last -f wtmp
root     pts/1        :0.0             Tue Apr  1 07:42   still logged in  
root     pts/0        :0.0             Tue Apr  1 07:38   still logged in  
root     tty1         :0               Tue Apr  1 07:34   still logged in  
reboot   system boot  2.6.32-358.el6.x Tue Apr  1 07:33 - 07:43  (00:09)   
root     pts/0        :0.0             Mon Mar 31 23:49 - down   (00:30)   
root     tty1         :0               Mon Mar 31 23:48 - down   (00:30)   
reboot   system boot  2.6.32-358.el6.x Mon Mar 31 23:48 - 00:19  (00:31)   
root     pts/2        :0.0             Sun Mar 30 11:38 - 11:38  (00:00)   

==================================

[root@localhost Desktop]# last -f /var/log/wtmp > /tmp/wtmpMarch.txt
[root@localhost Desktop]# ls -ld /tmp/wtmpMarch.txt
-rw-r--r-- 1 root root 12435 Apr  3 08:36 /tmp/wtmpMarch.txt
[root@localhost Desktop]#
[root@localhost Desktop]# less /tmp/wtmpMarch.txt
[root@localhost Desktop]# tail -4 /tmp/wtmpMarch.txt
reboot   system boot  2.6.32-358.el6.x Sat Feb  8 23:42 - 23:49  (00:07)   
reboot   system boot  2.6.32-358.el6.x Sat Feb  8 23:40 - 23:41  (00:01)   

wtmp begins Sat Feb  8 23:40:05 2014
[root@localhost Desktop]#




Love Sharing
Amit Chopra



How to check ntp version + redhat linux

Hi Friends,

Same as HP UNIX, ntp version can be checked from ntpq prompt. Please go to ntpq prompt, write version there, it will give the output which you are using.

attaching screen shot.






Love Sharing
Amit Chopra



Wednesday, April 2, 2014

How to check version of NTP + Hp UX

Hello Friends,

We were looking for NTP version installed on the hp ux server. but couldn't get the information using swinstall, swlist -l product, swlist -l fileset, swlist -l patch, swagent.log. After trying so many things we checked in

#ntpq
ntpq"prompt'
ntpq"prompt" version
"it will show the installed version of NTP"

NTP prompt is ntp"greater than arrow sign", {I dont know how can i enable the arrow signs here, as greater than or smaller than sign changes into some code after clicking on publish of post}
. Sorry for the inconvenience.

1. Somewhere i read on google, that "ntpd -v" will show the version of NTP. Or /usr/sbin/ntpd -v or /usr/sbin/xntpd -v will show the version but this was not available on  V3 and V2.

2. Also the /etc/rc.config.d/netdaemon files and /etc/ntp.conf  do not carry exact information about the version of NTP.

3. yes also Read on HP forum that the by default version of NTP which comes with 11.31 V3 is NTP verison 3.5.

4. The latest release from HP is version 4.2.6, not yet recommended by HP to upgrade the version.

5. Now to automate and check the version on large number of server, we can use a script or command. like below :-

If you are using any tool to get all information from all server from one server then it is very fine. you can use below command and extract information from the same.

 #"hostname; echo 'version' |ntpq; echo 'ntpversion' |ntpq"

or

#echo 'version' |ntpq

it will show the output, you not need to  give an input manually to ntpq prompt. after this you can redirect the output to some file also.

6. echo 'version' is giving its output to ntpq prompt and using this we can get the version of NTP.


Love Sharing
Amit Chopra


Tuesday, April 1, 2014

wtmpx data file Huge size + solaris

Hi Friends,

/var/adm/wtmpx  is a file, which keeps login details of the users and also carries shutdown, reboot of the server details. We faced File system full issue due to it. Our File system was total of size 15 GB, and the wtmpx file was occupying 12 GB of space and there were some other files which were occupying few spaces in MBs.

 and we were also not having space on other LVs, so that we could move the wtmp file and then compress the same. We could not stop the wtmp file logging.

a. We copied the same in text format using below command on /temp.

#/usr/lib/acct/fwtmp "<" /var/adm/wtmpx ">" /temp/wtmp.txt (the first sign used is "less than" and the second sign used is "greater than". First one is used to read the content and second one is used to to fwd the content of wtmpx file to text file )

We can also use the last -f command to read the files utmp, wtmp, btmp. As these file types are data type so should not be read with vi, more, cat.
#
#last -f /var/adm/wtmp or
#last -f /var/log/wtmp


this copied the content of wtmp file in /temp/wtmp.txt. You can name this file as per your wish.

this wtmp.txt file size was around 4.8G as it copied all the content of wtmp file of 12 GB.

b. We can monitor the /temp File system and we can also tail -f /temp/wtmp.txt file to check whether the files is proper or not. Now we can read the file as well.

c. tar/ compress/gzip the file, I gzipped the file

#gzip /temp/wtmp.txt

the size of above file became 250MB approx.

d. Now truncate the /var/adm/wtmp file or pass null value to the same like

#> /var/adm/wtmp :- this doesnt kill the process, but it empties the file.

e. File system size reduced.

f. Now moved the wtmp.txt file back to /var/adm/


It was a good learning. the FS size reduced and /var was available for use.




Love Sharing
Amit Chopra




#