How to check logs in ubuntu

Goto /var/log diretcory

$ cd /var/log

List files and directories date wise descending order

$ ls -alt

ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for ‘reverse’.

check which website get more load on ubuntu

System Load or System Load Average

It is run-queue i.e a queue of processes waiting for a resource(cpu, i/o etc.) to become available .

Consider a single-core cpu as a single lane of traffic with bridge and process as cars.

Now in this situation System load is

  • 0.0 – If there is no traffic on the road.
  • 1.0 -If the traffic on the road is exactly the capacity of bridge.
  • More than 1 – If the traffic on road is higher than the capacity of bridge and cars have to wait to pass trough the bridge.

This number is not normalized according to your cpu. In Multiprocessor system, load 2 mean 100 % utilization of we are using dual-core processor, load 4 means 100% utilization if we are using quad-core.

You can get your system load using

  • uptime
  • cat /proc/loadavg
  • top$uptime 22:49:47 up 11:47, 4 users, load average: 2.20, 1.03, 0.82

Here the last three number representing the system load average for 1, 5 and 15 minutes respectively.

The example above indicates that on average there were 2.20 processes waiting to be scheduled on the run-queue measured over the last minute.

check which website get more load on ubuntu

This works very well:

 while true; do uptime >> uptime.log; sleep 1; done
  • This will log your cpu load every second and append it to a file uptime.log.You can then import this file into Gnumeric or the OpenOffice spreadsheet to create a nice graph (select ‘separated by spaces’ on import).

As Scaine noticed, this won’t be enough to diagnose the problem. So, additionally, run this (or use his answer for this part):

while true; do (echo "%CPU %MEM ARGS $(date)" && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> ps.log; sleep 5; done
  • This will append the Top 10 most CPU hungry processes to a file ps.log every five seconds.Note that this is not the full boat-load of information top would give you. This is just the top 10, and just their CPU Usage, Memory Usage and the first argument (i.e. their command without further arguments, as in /usr/bin/firefox)

After you’ve used a Spreadsheet to create a graph to see when your CPU load went through the roof, you can then search this file for the nearest time to see what process has caused it.

This is what those files will look like:

uptime.log

~$ cat uptime.log 
 22:57:42 up 1 day,  4:38,  4 users,  load average: 1.00, 1.26, 1.21
 22:57:43 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 22:57:44 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 22:57:45 up 1 day,  4:38,  4 users,  load average: 0.92, 1.24, 1.21
 ...

ps.log

%CPU %MEM ARGS Mo 17. Jan 23:09:47 CET 2011
 0.7  0.9 /usr/bin/compiz
 0.8  0.5 /usr/lib/gnome-panel/clock-applet
 1.1  1.7 /opt/google/chrome/chrome
 1.2  0.3 /usr/bin/pulseaudio
 1.8  4.0 /opt/google/chrome/chrome
 2.6  1.5 /opt/google/chrome/chrome
 2.6  3.2 /usr/bin/google-chrome
 3.6  2.6 /opt/google/chrome/chrome
 4.9  1.5 /usr/bin/X
 5.7  1.6 /opt/google/chrome/chrome
%CPU %MEM ARGS Mo 17. Jan 23:09:48 CET 2011
 0.7  0.9 /usr/bin/compiz
 0.8  0.5 /usr/lib/gnome-panel/clock-applet
 1.0  1.7 /opt/google/chrome/chrome
 1.2  0.3 /usr/bin/pulseaudio
 1.8  4.0 /opt/google/chrome/chrome
 2.6  1.5 /opt/google/chrome/chrome
 2.6  3.2 /usr/bin/google-chrome
 3.6  2.6 /opt/google/chrome/chrome
 4.9  1.5 /usr/bin/X
 5.7  1.6 /opt/google/chrome/chrome
 ...

remove all mail services from ubuntu

remove sendmail ubuntu

$ sudo apt-get purge sendmail*
$ apt-get remove sendmail
$ apt-get purge sendmail

remove postfix ubuntu

$ sudo apt remove postfix && apt purge postfix
$ sudo autoremove

When I install Postfix again, the installation does not ask the questions like on the first installation. I still have my previous configuration. Why can not I reset the Postfix configuration ?

If I reconfigure Postfix, I still have the previous configuration :

$ sudo dpkg-reconfigure postfix

remove mailutils ubuntu

$ sudo apt-get remove  mailutils
$ sudo apt-get remove --auto-remove mailutils
$ sudo apt-get purge mailutils
$ sudo apt-get purge --auto-remove mailutils

how to change email id in ubuntu server

By default, any email sent by system is sent to root@hostname. So critical server errors, log errors, corn jobs alerts e.t.c all are sent to this default email address. To change it to different appropriate email id, we can do this by two ways.

By updating email aliases file:

For this example, lets set email to system@mydomain.com

Step 1 : edit /etc/aliases file 

$ vi /etc/aliases

Add email ids at the bottom of the file.

postmaster: system@mydmomain.com

To add multiple email ids, we can simply separate them by comma.

postmaster: system@mydomain.com, linux@mydomain.com

linux@mydomain.com is second email id 

Step 2: Run the aliases command, to compile aliases file. 

$ newaliases

Step 3: Restart postfix server.

service postfix restart

Second way:

We can simply create .forward file to the folder root and add email address there.

$ vi /root/.forward
system@mydomain.com

Restart postfix server
$ service postfix restart.

How to change phpmyadmin url of ubuntu aws server

How to change phpmyadmin url of ubuntu aws server

http://www.domain.in/dbaditya/

this is the url

in this video we change dbaditya to newname

  1. login into server using putty
  2. cd /etc
  3. cd phpmyadmin
  4. ls
  5. sudo nano apache.conf
  6. modify this line Alias /dbaditya /usr/share/phpmyadmin
  7. ctrl + x and press y for exit
  8. sudo service apache2 restart for restart the apache service

Note: top command to show process monitor of server

q used for quit from top command window/screen

http://www.domain.in/mynewdata/
Done URL succcessfully changed

change default auto login user in ubuntu

sudo leafpad /etc/lxdm/default.conf
sudo leafpad /etc/lightdm/fileexample.conf

In the fist few line, you will see something like autologin=username change it to the original state of # autologin=dgod. Save the file, and then reboot your machine.

autologin-user=username
autologin-user-timeout=0

Using privileged admin account open up terminal or your favorite text file editor and edit the /etc/gdm3/custom.conf configuration file. Change from:

[daemon]
# Uncoment the line below to force the login screen to use Xorg
#WaylandEnable=false

# Enabling automatic login
#  AutomaticLoginEnable = true
#  AutomaticLogin = user1

php mail function not working on ubuntu server

I want to enable the simple php mail() function on an Ubuntu server.

three steps

sudo apt-get install sendmail
sudo sendmailconfig (answer Yes to everything)
sudo service apache2 restart

wget command in ubuntu

GNU Wget is a command-line utility for downloading files from the web. With Wget, you can download files using HTTP, HTTPS, and FTP protocols. Wget provides a number of options allowing you to download multiple files, resume downloads, limit the bandwidth, recursive downloads, download in the background, mirror a website and much more.

Installing Wget on Ubuntu and Debian 

sudo apt install wget

Installing Wget on CentOS and Fedora

sudo yum install wget

The wget utility expressions take the following form:

$ wget [options] [url]

Copy

  • options – The Wget options
  • url – URL of the file or directory you want to download or synchronize.

How to Download a File with Wget

In it’s simplest form when used without any option, wget will download the resource specified in the [url] to the current directory.

In the following example we are downloading the Linux kernel tar archive:

$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

Using Wget Command to Save the Downloaded File Under Different Name

To save the downloaded file under a different name, pass the -O option followed by the chosen name:

$ wget -O latest-hugo.zip https://github.com/gohugoio/hugo/archive/master.zip

The command above will save the latest hugo zip file from GitHub as latest-hugo.zip instead of its original name.

Using Wget Command to Download a File to a Specific Directory

By default, Wget will save the downloaded file in the current working directory. To save the file to a specific location, use the -P option:

$ wget -P /mnt/iso http://mirrors.mit.edu/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso

How to Limit the Download Speed with Wget

To limit the download speed, use the --limit-rate option. By default, the speed is measured in bytes/second. Append k for kilobytes , m for megabytes and g for gigabytes.

The following command will download the Go binary and limit the download speed to 1mb:

$ wget --limit-rate=1m https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

This option is useful when you don’t want wget to consume all the available bandwidth.

How to Resume a Download with Wget

You can resume a download using the -c option. This is useful if your connection drops during a download of a large file, and instead of starting the download from scratch, you can continue the previous one.

In the following example we are resuming the download of the Ubuntu 18.04 iso file:

$ wget -c http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso

If the remote server does not support resuming downloads, Wget will start the download from the beginning and overwrite the existing file.

How to Download in Background with Wget

To download in the background ,use the -b option. In the following example, we are downloading the OpenSuse iso file in the background:

$ wget -b https://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso

By default, the output is redirected to wget-log file in the current directory. To watch the status of the download, use the tail command:

$ tail -f wget-log

How to change the Wget User-Agent of Wget

Sometimes when downloading a file, the remote server may be set to block the Wget User-Agent. In situations like this to emulate a different browser pass the -U option.

wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://wget-forbidden.com/

The command above will emulate Firefox 60 requesting the page from wget-forbidden.com

How to Download Multiple Files with Wget

If you want to download multiple files at once, use the -i option followed by the path to a local or external file containing a list of the URLs to be downloaded. Each URL needs to be on a separate line.

In the following example we are downloading the Arch Linux, Debian, and Fedora iso files with URLs specified in the linux-distros.txt file:

$ wget -i linux-distros.txt

linux-distros.txt

http://mirrors.edge.kernel.org/archlinux/iso/2018.06.01/archlinux-2018.06.01-x86_64.iso
https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
https://download.fedoraproject.org/pub/fedora/linux/releases/28/Server/x86_64/iso/Fedora-Server-dvd-x86_64-28-1.1.iso

Copy

If you specify - as a filename, URLs will be read from the standard input.

Using Wget Command to Download via FTP

To download a file from a password-protected FTP server, specify the username and password as shown below:

$ wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD ftp://ftp.example.com/filename.tar.gz

Using Wget Command to Create a Mirror of a Website

To create a mirror of a website with Wget, use the -m option. This will create a complete local copy of the website by following and downloading all internal links as well as the website resources (JavaScript, CSS, Images).

$ wget -m https://example.com

If you want to use the downloaded website for local browsing, you will need to pass a few extra arguments to the command above.

$ wget -m -k -p https://example.com

The -k option will cause Wget to convert the links in the downloaded documents to make them suitable for local viewing. The -p option will tell wget to download all necessary files for displaying the HTML page.

How to Skip Certificate Check with Wget

If you want to download a file over HTTPS from a host that has an invalid SSL certificate, use the --no-check-certificate option:

$ wget --no-check-certificate https://domain-with-invalid-ss.com

How to Download to Standard Output with Wget

In the following example, Wget will quietly ( flag -q) download and output the latest WordPress version to stdout ( flag -O -) and pipe it to the tar utility which will extract the archive to the /var/www directory.

$ wget -q -O - "http://wordpress.org/latest.tar.gz" | tar -xzf - -C /var/www

mysql export/import database command line ubuntu

Log in a MySQL root user:

$ mysql -u user -p

Run the SHOW DATABASES command:

mysql> SHOW DATABASES;

EXPORT from MySql

$ mysqldump -u [username] -p [database name] > [database name].sql

IMPORT in MySql

$ mysql -u [username] -p newdatabase < [database name].sql