Skip to content

Recent Articles

26
Jul

Log MySQL Queries

If you want to log MySQL Queries log in to your mysql client and run:

mysql> SHOW VARIABLES LIKE "general_log%";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| general_log      | ON                    |
| general_log_file | /var/db/mysql/machine.log |
+------------------+-----------------------+
2 rows in set (0.00 sec)
 
mysql>
mysql>
mysql> SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)

Then to see the queries as soon as they run do tail on the log.

tail -f /var/db/mysql/machine.log

After you’ve seen the queries and you’ve completed the debug task it is a good practice do disable logging:

mysql> SET GLOBAL general_log = 'OFF';
Query OK, 0 rows affected (0.02 sec)
23
Jul

Check if a Service is Running Using Telnet and How to Quit Telnet Session

Telnet is not used that much anymore. To connect to a managed switch CLI this could be your only options. But then telnet has other use: you can check if a service run on a port on a remote machine.

For example to check if mysql server is running on a remote machine:

 # telnet 10.0.0.20 3306
Trying 10.0.0.20...
Connected to 10.0.0.20.
Escape character is '^]'.
J
5.6.36�-;#:<]A�w7HDZ{|{tV24mysql_native_password

To check if ssh is running on a remote machine:

 # telnet 10.0.0.20 22
Trying 10.0.0.20...
Connected to 10.0.0.20.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.2
 
Protocol mismatch.
Connection closed by foreign host.

You should get some reply from the remote machine with a text.

If you get no reply that means either that the service is not running or the service is running on other port (in case of SSH) or that the remote machine’s firewall blocks the access from outside to that service.

Now, if you want to quit telnet you will notice Ctrl + C is not working.

In order to quit telnet press Ctrl + ] to get to telnet console then type: quit

14
Jul

Find Out the Version of Your Ubuntu Linux

To find out which version is the Ubuntu Linux installed on your machine you must use the lsb_release command:

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.04
Release:	17.04
Codename:	zesty
10
Feb

My Ubuntu 16.04 Networking is configured but I cannot find config files

If your Ubuntu machine has networking configured but there’s nothing in: /etc/network/interfaces (maybe only loopback interface is configured there) and there’s no file in /etc/network/interfaces.d then maybe the network was configured via Ubuntu’s GUI (Network Manager).

In that case the config file is located in /etc/NetworkManager directory.

10
Feb

Configure Networking in Ubuntu 16.04 Server

One way on some Ubuntu versions was to edit /etc/network/interfaces and add the the configuration of network interface. On Ubuntu 16.04 I’ve don the following setup:

# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

And then we create a file in /etc/network/interfaces.d called enp0s3:

# cat enp0s3
auto enp0s3
iface enp0s3 inet static
  address 10.0.0.211
  broadcast 10.0.0.255
  netmask 255.255.255.0
  post-up route add default gw 10.0.0.1
  pre-down route del default gw 10.0.0.1
 
dns-nameservers 10.0.0.1
10
Feb

Configure Networking in OpenSUSE Linux with manual IPv4

Here is a Quick Guide to configure networking in OpenSUSE Linux using manual IPv4.

First let’s see where config files are located.

# ls /etc/sysconfig/network/ifcfg-*
/etc/sysconfig/network/ifcfg-eth0  /etc/sysconfig/network/ifcfg-lo
linux-t003:/home/ovi #

Edit /etc/sysconfig/network/ifcfg-eth0 file and add:

BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='10.0.1.31/24'
MTU=''
NAME='82540EM Gigabit Ethernet Controller'
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'

Edit /etc/sysconfig/network/routes file and add:

default 10.0.1.1 -	-

Edit /etc/resolv.conf and add:

nameserver 10.0.1.1

Then we need to restart network service:

service network restart
24
Oct

Rename Multiple Files in Linux

To rename multiple files in Linux run from the command line:

for f in *.cc; do mv -- "$f" "${f%.cc}.cpp"; done

Previous command will rename all .cc files into .cpp files.

Note: It will not work recursively. To rename recursively use the following command:

find ./ -type f -exec rename 's/.mm/.cpp/' '{}' \;
25
Apr

Add an user to Ubuntu Linux from command line

If you want to add an user to your Ubuntu Linux machine here is what you need to do. Login as root (or use sudo) and then run (as root):

useradd -d /home/john -m john
passwd john
usermod -aG sudo john

If you are not root run:

sudo useradd -d /home/john -m john
sudo passwd john
sudo usermod -aG sudo john

In our example john is the user we want to add. Last command (usermod) will allow our user to run root commands via sudo.

25
Apr

Becoming root on Ubuntu Linux

If you are using Ubuntu Linux you’ve logged in as an user. If you want to become root so you won’t have to input sudo on every command you run, here’s what you need to do:

sudo su

or

sudo su -

which is probably what you really want. su – will invoke a login shell after switching the user. Just running su with no parameters will just switch the user (keeping the old shell and environment variables).

You can also run:

sudo -i

Then you get the root prompt and you will be able to run any command as root.

25
Apr

Dealing with “Bad: new password is too simple” issue on Ubuntu Linux

Let’s say you’ve booted with Live Ubuntu CD/DVD and you want to change the password of your user which is called ubuntu on Live Ubuntu CD/DVD. If you run:

passwd

you might get an error like:

You must choose a longer password

or:

Bad: new password is too simple.

You can bypass those checks by running passwd as a root with sudo:

sudo passwd

That way you will be allowed to enter short or too simple passwords which sometimes you need for testing purposes. Of course you will not use such passwords on machines connected to the internet but maybe only on test machines, maybe in virtualized environments.