Wednesday, December 28, 2016

How to monitor CPU Temperature Including Voltage and Fan Speed using lm-sensors in linux ?

How To Install lm-sensors on a Ubuntu / Debian Linux



To install lm-sensors on  a Ubuntu or Debian Linux to monitor fan speed and cpu temp info, type:

dev@linuxforfreshers.com:~$ sudo apt-get install lm-sensors
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
  cairo-dock-core cairo-dock-data cairo-dock-plug-ins-data
  cairo-dock-plug-ins-integration compiz-plugins hplip-data libetpan15
  libgldi3 libndesk-dbus-glib1.0-cil libndesk-dbus1.0-cil python-pexpect
  python-renderpm python-reportlab python-reportlab-accel
Use 'apt-get autoremove' to remove them.
Suggested packages:
  fancontrol sensord read-edid i2c-tools
The following NEW packages will be installed:
  lm-sensors
0 upgraded, 1 newly installed, 0 to remove and 208 not upgraded.
Need to get 84.6 kB of archives.
After this operation, 423 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/universe lm-sensors amd64 1:3.3.4-2ubuntu1 [84.6 kB]
Fetched 84.6 kB in 0s (138 kB/s)     
Selecting previously unselected package lm-sensors.
(Reading database ... 442441 files and directories currently installed.)
Preparing to unpack .../lm-sensors_1%3a3.3.4-2ubuntu1_amd64.deb ...
Unpacking lm-sensors (1:3.3.4-2ubuntu1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up lm-sensors (1:3.3.4-2ubuntu1) ...






Install lm_sensors on a CentOS / RHEL
Type the following yum command to install software on CentOS / RHEL / Fedora Linux dev@linuxforfreshers.com:~$ sudo yum install lm_sensors

How to use to use lm-sensors on a Ubuntu or Debian?

Run the following command first time only and simply press ENTER to accept the defaults:
dev@linuxforfreshers.com:~$ sudo sensors-detect

# sensors-detect revision 4609 (2007-07-14 09:28:39 -0700)


This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.


We can start with probing for (PCI) I2C or SMBus adapters.
Do you want to probe now? (YES/no):
Probing for PCI bus adapters...
Use driver `i2c-i801' for device 0000:00:1f.3: Intel 82801G ICH7


We will now try to load each adapter module in turn.
Module `i2c-i801' already loaded.
If you have undetectable or unsupported adapters, you can have them
scanned by manually loading the modules before running this script.


To continue, we need module `i2c-dev' to be loaded.
Do you want to load `i2c-dev' now? (YES/no):
Module loaded successfully.


We are now going to do the I2C/SMBus adapter probings. Some chips may
be double detected; we choose the one with the highest confidence
value in that case.
If you found that the adapter hung after probing a certain address,
you can specify that address to remain unprobed.


Next adapter: saa7133[0] (i2c-0)
Do you want to scan it? (YES/no/selectively):
Client found at address 0x47
Handled by driver `ir-kbd-i2c' (already loaded), chip type `Pinnacle PCTV'
    (note: this is probably NOT a sensor chip!)
Client found at address 0x4b
Handled by driver `tuner' (already loaded), chip type `tda8290+75a'
    (note: this is probably NOT a sensor chip!)
Client found at address 0x50
Probing for `Analog Devices ADM1033'...                     No
Probing for `Analog Devices ADM1034'...                     No
Probing for `SPD EEPROM'...                                 No
Probing for `EDID EEPROM'...                                No


Next adapter: SMBus I801 adapter at 4000 (i2c-1)
Do you want to scan it? (YES/no/selectively):
Client found at address 0x2e
Probing for `Myson MTP008'...                               No
Probing for `National Semiconductor LM78'...                No
Probing for `National Semiconductor LM78-J'...              No
Probing for `National Semiconductor LM79'...                No
Probing for `National Semiconductor LM80'...                No
Probing for `National Semiconductor LM85 or LM96000'...     No
Probing for `Analog Devices ADM1027, ADT7460 or ADT7463'... No
Probing for `SMSC EMC6D100, EMC6D101 or EMC6D102'...        No
Probing for `Analog Devices ADT7462'...                     No
Probing for `Analog Devices ADT7467 or ADT7468'...          No
Probing for `Analog Devices ADT7470'...                     No
Probing for `Analog Devices ADT7473'...                     No
Probing for `Analog Devices ADT7475'...                     No
Probing for `Analog Devices ADT7476'...                     No
Probing for `Andigilog aSC7611'...                          No
Probing for `Andigilog aSC7621'...                          Success!
    (confidence 5, driver `to-be-written')
Probing for `National Semiconductor LM87'...                No
Probing for `National Semiconductor LM93'...                No
Probing for `Winbond W83781D'...                            No
Probing for `Winbond W83782D'...                            No
Probing for `Winbond W83792D'...                            No
Probing for `Winbond W83793R/G'...                          No
Probing for `Winbond W83791SD'...                           No
Probing for `Winbond W83627HF'...                           No
Probing for `Winbond W83627EHF'...                          No
Probing for `Winbond W83627DHG'...                          No
Probing for `Asus AS99127F (rev.1)'...                      No
Probing for `Asus AS99127F (rev.2)'...                      No
Probing for `Asus ASB100 Bach'...                           No
Probing for `Winbond W83L785TS-S'...                        No
Probing for `Analog Devices ADM9240'...                     No
Probing for `Dallas Semiconductor DS1780'...                No
Probing for `National Semiconductor LM81'...                No
Probing for `Analog Devices ADM1026'...                     No
Probing for `Analog Devices ADM1025'...                     No
Probing for `Analog Devices ADM1024'...                     No
Probing for `Analog Devices ADM1029'...                     No
Probing for `Analog Devices ADM1030'...                     No
Probing for `Analog Devices ADM1031'...                     No
Probing for `Analog Devices ADM1022'...                     No
Probing for `Texas Instruments THMC50'...                   No
Probing for `Analog Devices ADM1028'...                     No
Probing for `ITE IT8712F'...                                No
Probing for `SMSC DME1737'...                               No
Probing for `Fintek F75373S/SG'...                          No
Probing for `Fintek F75375S/SP'...                          No
Probing for `Fintek F75387SG/RG'...                         No
Probing for `Winbond W83791D'...                            No
Client found at address 0x44
Probing for `Maxim MAX6633/MAX6634/MAX6635'...              No
Client found at address 0x50
Probing for `Analog Devices ADM1033'...                     No
Probing for `Analog Devices ADM1034'...                     No
Probing for `SPD EEPROM'...                                 Yes
    (confidence 8, not a hardware monitoring chip)
Probing for `EDID EEPROM'...                                No


Some chips are also accessible through the ISA I/O ports. We have to
write to arbitrary I/O ports to probe them. This is usually safe though.
Yes, you do have ISA I/O ports even if you do not have any ISA slots!
Do you want to scan the ISA I/O ports? (YES/no):
Probing for `National Semiconductor LM78' at 0x290...       No
Probing for `National Semiconductor LM78-J' at 0x290...     No
Probing for `National Semiconductor LM79' at 0x290...       No
Probing for `Winbond W83781D' at 0x290...                   No
Probing for `Winbond W83782D' at 0x290...                   No
Probing for `Silicon Integrated Systems SIS5595'...         No
Probing for `VIA VT82C686 Integrated Sensors'...            No
Probing for `VIA VT8231 Integrated Sensors'...              No
Probing for `IPMI BMC KCS' at 0xca0...                      No
Probing for `IPMI BMC SMIC' at 0xca8...                     No


Some Super I/O chips may also contain sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no):
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor'...                   No
Trying family `SMSC'...                                     Yes
Found `SMSC LPC47M182 Super IO Fan Sensors'                
    (but not activated)
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor'...                   No
Trying family `SMSC'...                                     No
Trying family `VIA/Winbond/Fintek'...                       No
Trying family `ITE'...                                      No


Some CPUs or memory controllers may also contain embedded sensors.
Do you want to scan for them? (YES/no):
AMD K8 thermal sensors...                                   No
Intel Core family thermal sensor...                         Success!
    (driver `coretemp')
Intel AMB FB-DIMM thermal sensor...                         No


Now follows a summary of the probes I have just done.
Just press ENTER to continue:


Driver `to-be-written' (should be inserted):
  Detects correctly:
  * Bus `SMBus I801 adapter at 4000'
    Busdriver `i2c-i801', I2C address 0x2e
    Chip `Andigilog aSC7621' (confidence: 5)


Driver `coretemp' (should be inserted):
  Detects correctly:
  * Chip `Intel Core family thermal sensor' (confidence: 9)


I will now generate the commands needed to load the required modules.
Just press ENTER to continue:


To make the sensors modules behave correctly, add these lines to
/etc/modules:


#----cut here----
# I2C adapter drivers
i2c-i801
# Chip drivers
# no driver for Andigilog aSC7621 yet
coretemp
#----cut here----


Do you want to add these lines to /etc/modules automatically? (yes/NO)


This is an interactive program that will walk you through the process of scanning your system for various hardware monitoring chips, or sensors, supported by libsensors, or more generally by the lm_sensors tool suite. For my system coretemp and i2c-i801 driver need to loaded in order to see sensors data. Type ‘YES” to update /etc/modules files. Now you need to reboot the box.

How do I read sensors chip data such as temperature and fan speed?

Simply run the following command to see CPU temp and fan speed and other data:

dev@linuxforfreshers.com:~$ sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +44.0°C  (high = +74.0°C, crit = +100.0°C)
Core 1:       +42.0°C  (high = +74.0°C, crit = +100.0°C)

nouveau-pci-0100
Adapter: PCI adapter
temp1:        +62.0°C  (high = +95.0°C, hyst =  +3.0°C)
                       (crit = +105.0°C, hyst =  +5.0°C)
                       (emerg = +135.0°C, hyst =  +5.0°C)


Or

dev@linuxforfreshers.com:~$ sensors | egrep -i --color 'core|fan|temp'
coretemp-isa-0000
Core 0:       +44.0°C  (high = +74.0°C, crit = +100.0°C)
Core 1:       +42.0°C  (high = +74.0°C, crit = +100.0°C)
temp1:        +61.0°C  (high = +95.0°C, hyst =  +3.0°C)


Tip: Watch your sensors data in real time
dev@linuxforfreshers.com:~$ watch -db sensors

Uninstall lm-sensors

To remove just lm-sensors package itself from Ubuntu 14.04 (Trusty Tahr) execute on terminal:
sudo apt-get remove lm-sensors

Uninstall lm-sensors and it's dependent packages

To remove the lm-sensors package and any other dependant package which are no longer needed from Ubuntu Trusty.
sudo apt-get remove --auto-remove lm-sensors

Purging lm-sensors

If you also want to delete configuration and/or data files of lm-sensors from Ubuntu Trusty then this will work:
sudo apt-get purge lm-sensors
To delete configuration and/or data files of lm-sensors and it's dependencies from Ubuntu Trusty then execute:
sudo apt-get purge --auto-remove lm-sensors




how to check if a package is installed or not In Ubuntu ?

If you’re managing Debian or Ubuntu servers, probably, you may use dpkg or apt-get commands often. These two commands are used to install, remove, update packages.

In this brief tutorial, let us see how to check if a package is installed or not in DEB based systems.
To check whether a particular package for example firefox, is installed or not using command:

dpkg -s firefox
Sample output:
 Package: firefox
 Status: install ok installed
 Priority: optional
 Section: web
 Installed-Size: 93339
 Maintainer: Ubuntu Mozilla Team <ubuntu-mozillateam@lists.ubuntu.com>
 Architecture: amd64
 Version: 35.0+build3-0ubuntu0.14.04.2
 Replaces: kubuntu-firefox-installer
 Provides: gnome-www-browser, iceweasel, www-browser
 Depends: lsb-release, libasound2 (>= 1.0.16), libatk1.0-0 (>= 1.12.4), libc6 (>= 2.17), libcairo2 (>= 1.2.4), libdbus-1-3 (>= 1.0.2), libdbus-glib-1-2 (>= 0.78), libfontconfig1 (>= 2.9.0), libfreetype6 (>= 2.2.1), libgcc1 (>= 1:4.1.1), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.37.3), libgtk2.0-0 (>= 2.24.0), libpango-1.0-0 (>= 1.22.0), libpangocairo-1.0-0 (>= 1.14.0), libstartup-notification0 (>= 0.8), libstdc++6 (>= 4.6), libx11-6, libxcomposite1 (>= 1:0.3-1), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxrender1, libxt6
 Recommends: xul-ext-ubufox, libcanberra0, libdbusmenu-glib4, libdbusmenu-gtk4
 Suggests: ttf-lyx
 Conffiles:
 /etc/firefox/syspref.js 09e457e65435a1a043521f2bd19cd2a1
 /etc/apport/blacklist.d/firefox ee63264f847e671832d42255912ce144
 /etc/apport/native-origins.d/firefox 7c26b75c7c2b715c89cc6d85338252a4
 /etc/apparmor.d/usr.bin.firefox f54f7a43361c7ecfa3874abca2f292cf
 Description: Safe and easy web browser from Mozilla
 Firefox delivers safe, easy web browsing. A familiar user interface,
 enhanced security features including protection from online identity theft,
 and integrated search let you get the most out of the web.
 Xul-Appid: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
As you see in the above output, the firefox is installed.
Also, you can do the same using dpkg-query command. This command displays the decent output, and of course, you can wild cards too.

dpkg-query -l firefox
Sample output:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                 Version                 Architecture            Description
+++-====================================-=======================-=======================-=============================================================================
ii  firefox                              35.0+build3-0ubuntu0.14 amd64                   Safe and easy web browser from Mozilla
To list all installed package in your system, enter the following command
dpkg --get-selections
Sample output:
abiword                        install
abiword-common                    install
accountsservice                    install
acl                        install
adduser                        install
alsa-base                    install
alsa-utils                    install
anacron                        install
app-install-data                install
apparmor                    install
.
.
.
zeitgeist                    install
zeitgeist-core                    install
zeitgeist-datahub                install
zenity                        install
zenity-common                    install
zip                        install
zlib1g:amd64                    install
zlib1g:i386                    install
The above might be very long depending upon the number of packages you have installed on your system.
You can also filter through grep to get results for the exact package you need. For example, I want to see which gcc packages are already installed on my system using dpkg command:

dpkg --get-selections | grep gcc
Sample output:
gcc                        install
gcc-4.8                        install
gcc-4.8-base:amd64                install
gcc-4.8-base:i386                install
gcc-4.9-base:amd64                install
gcc-4.9-base:i386                install
libgcc-4.8-dev:amd64                install
libgcc1:amd64                    install
libgcc1:i386                    install
Additionally, you can find location of the files within a package using the parameter “-L”.

dpkg -L gcc-4.8
Sample output:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/gcc-4.8-base
/usr/share/doc/gcc-4.8-base/README.Bugs
/usr/share/doc/gcc-4.8-base/NEWS.html
/usr/share/doc/gcc-4.8-base/quadmath
/usr/share/doc/gcc-4.8-base/quadmath/changelog.gz
/usr/share/doc/gcc-4.8-base/gcc
.
.
.
/usr/bin/x86_64-linux-gnu-gcc-4.8
/usr/bin/x86_64-linux-gnu-gcc-ar-4.8

/usr/bin/x86_64-linux-gnu-gcov-4.8

Friday, December 16, 2016

How to check sudo access available for a Normal user ?

Method 1:
sudo  -v

Example
deb@linuxforfreshers:~$ sudo  -v
Sorry, user deb may not run sudo on LINUXFORFRESHERS.

Method 2:
sudo -l This will list any sudo privileges you have.

Example:
deb@linuxforfreshers:~$ sudo -l
[sudo] password for deb:           
Sorry, user deb may not run sudo on LINUXFORFRESHERS.

Method 3:
If you are a root privileged user using following command u should get the which user has which sudo permissions
Syntax : sudo -l -U username

Example 1:
ram@linuxforfreshers:~$ sudo -l –U srini
User srini is not allowed to run sudo on LINUXFORFRESHERS.

Example 2:
ram@linuxforfreshers:~$ sudo -l -U ansible
Matching Defaults entries for ansible on LINUXFORFRESHERS:
    env_reset, pwfeedback, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User ansible may run the following commands on LINUXFORFRESHERS:
    (ALL : ALL) NOPASSWD: ALL









Friday, November 4, 2016

How do I display shell command history with date and time under UNIX or Linux operating systems?

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character. Defining the environment variable as follows
root@linuxforfreshers.com:~$ vim .bash_profile

$ HISTTIMEFORMAT="%d/%m/%y %T "
:wq
Or
root@linuxforfreshers.com:~$  echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
root@linuxforfreshers.com:~$ source .bash_profile
Where,
%d – Day
%m – Month
%y – Year
%T – Time
root@linuxforfreshers.com:~$  history
Sample outputs:

986  10/03/1104:31:36 memcached-tool  10.10.28.22:11211 stats
  987  10/03/1104:31:36 w
  988  10/03/1104:31:37 iostat
  989  10/03/1104:31:37 top
  990  10/03/1104:31:37 at
  991  10/03/1104:31:38 atop
  992  10/03/1104:31:40 collectl
  993  10/03/1104:31:41 grep CPU /proc/cpuinfo
  994  10/03/1104:31:45 vmstat 3 100
  995  10/03/1104:31:55 sar -W -f /var/log/sa/sa12

References:
For more info type the following commands:
man bash
help history
man 3 strftime



Thursday, November 3, 2016

How to check which port number mysql server is running on linux ?

Method 1:

To find a listener on a port, do this:

root@linuxforfreshers.com:~$netstat -tln | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     

Or

root@linuxforfreshers.com:~$netstat -tlpn | grep mysql
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      870/mysqld


Method 2:

root@linuxforfreshers.com:~$grep port /etc/mysql/my.cnf
# One can use all long options that the program supports.
# It has been reported that passwords should be enclosed with ticks/quotes
port                 = 3306
port                 = 3306

Method 3:

Using Mysql Query
root@linuxforfreshers.com:~$  mysql –u username –p password

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |


+---------------+-------+