How to reset displays (monitors) settings for KDE Plasma and GNOME


Just Some Techie Notes!

In case your display arrangement or settings, e.g. when you have 3 screens and you are for some reason unable to reorganize them or change their settings, just reset your display settings:

For KDE Plasma:

rm -rf .local/share/kscreen


rm -rf .config/monitors.xml

Then just log out and back in.

That’s it! Enjoy!


View original post

Posted in Linux | Leave a comment

What to do when an SSH session hangs because of a network problem

It’s a very basic post, yet still useful!

Sometimes when you disconnect from a network or VPN or have any network connectivity problem in general that affects an established SSH connection to any of your servers, the terminal hangs for quite a while and you most probably just close the terminal and open a new one!

To avoid this, just do the following:

  1. Press Enter
  2. Press Shift + ~
  3. Press .

And the session is terminated without having to close the terminal window, that’s it!


Source: A comment on one of the StackOverflow posts that I can’t find right now!

Posted in Linux | Tagged , , | Leave a comment

How to reset root user password in MySQL 5.7+

Was too busy and haven’t written anything for quite a while!

Anyway, here is how to reset the root user password in MySQL 5.7 and later in a nutshell!

service mysql stop
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysqld_safe --skip-grant-tables &

mysql> UPDATE mysql.user SET authentication_string=PASSWORD('new-password') WHERE User='root';
mysql> exit;

mysqladmin -u root -p shutdown
service mysql start

That’s it, Enjoy!


Posted in Linux, MySQL | Tagged , , , , | Leave a comment

Create a filesystem report with Python

In many cases, data accumulates over time, and a lot of this data is not being accessed at all, sometimes for years. Accordingly, it would be great if you could create a report that shows which data, the last access date, its size and its owner.

With a few lines of Python, you can very efficiently traverse (I named it any mounted filesystem and save to a CSV file that has the following set of data:

  • Filename (with absolute path)
  • Last Access Date & Time
  • File Size (in bytes)
  • UID or username of the owner
import os, sys, time
import pathlib #pathlib only needed if fileowner will be a string not UID

for root, directories, filenames in os.walk(sys.argv[1]): #Loop through the filesystem or folder passed as an argument
    for filename in filenames:
            fullpath = os.path.join(root, filename) #Get full path of the file
            timelastaccessed = time.ctime(os.stat(fullpath).st_atime) #Get last access time
            filesize = os.stat(fullpath).st_size #Get file size
            fileowner = os.stat(fullpath).st_uid #Get file owner as a UID
            #fileowner = pathlib.Path(fullpath).owner() #Get file owner as a string, much slower
            print(fullpath, ",", timelastaccessed, ",", filesize, ",", fileowner, sep='')  #Format to output in CSV
        except OSError:
            print("Path does not exist or is inaccessible") #In case the file was inaccessible
        except UnicodeEncodeError:
            print("Encoding Error") #In case of files with names that throw a UnicodeEncodeError exception

To execute, just run:

python3 filesystem_or_folder >> output.csv

The above outputs the UID, but if you want to output the username itself, just comment the fileowner = os.stat(xxxxx) and uncomment the next line that uses pathlib

You can then import that CSV file into any available analytics platform like PowerBI and do your magic!

That’s it! Enjoy!

Posted in Linux | Tagged , , , , | Leave a comment

Script to count number of logged in users to OpenVPN

To get that information you need to query your openvpn-status.log file, which usually resides in /var/log/openvpn/openvpn-status.log.

A normal cat will show the following:

Updated,Wed Mar 5 11:57:51 2019
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
someuser,someip:55530,100686479,319036434,Tue Mar 5 03:22:04 2019
someuser,someip:58064,23120958,141190549,Tue Mar 5 12:30:05 2019
someuser,someip:7115,18011423,65882394,Tue Mar 5 14:26:00 2019
someuser,someip:4463,79682826,444263153,Tue Mar 5 08:01:52 2019
Virtual Address,Common Name,Real Address,Last Ref,someuser,someip:47080,Tue Mar 5 12:51:44 2019
Max bcast/mcast queue length,46

The command to get number of connected users at any given time is:

echo $((sed '/ROUTING TABLE/Q' /var/log/openvpn/openvpn-status.log | wc -l-3)) "users connected on" date +"%m-%d-%Y %H:%M"
4 users connected on 03-05-2019 13:23 #Just an example, not real value

This basically parses the text till reaching the line with “ROUTING TABLE”, then counts the lines and subtracts 3 from them due to the first unneeded 3 lines

That’s it! Enjoy!


Posted in Linux | Tagged , , | Leave a comment