Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Recent Posts

Pages: 1 ... 4 5 [6] 7 8 ... 10
51
General Linux / Vim Tutorials to Jumpstart Your Editor Skills
« Last post by akhilt on September 02, 2018, 10:15:35 am »
Essential Vim Editor Navigation Fundamentals

Vim editor is hands-down the best editor on Unix and Linux environment. These tutorials will help you become proficient in the Vim editor. If you are spending lot of time on Unix environment, you should become comfortable in the Vim editor.

Navigation is a vital part of text editing. To be very productive, you should be aware of all possible navigation shortcuts in your editor. In this article, let us review the following 8 Vi / Vim navigation options.

1. Line navigation
2. Screen navigation
3. Word navigation
4. Special navigation
5. Paragraph navigation
6. Search navigation
7. Code navigation
8. Navigation from command line

1. Vim Line Navigation

Following are the four navigation that can be done line by line.

    k – navigate upwards
    j – navigate downwards
    l – navigate right side
    h – navigate left side

By using the repeat factor in VIM we can do this operation for N times. For example, when you want to
go down by 10 lines, then type “10j”.

Within a line if you want to navigate to different position, you have 4 other options.

    0 – go to the starting of the current line.
    ^ – go to the first non blank character of the line.
    $ – go to the end of the current line.
    g_ – go to the last non blank character of the line.

2. Vim Screen Navigation

Following are the three navigation which can be done in relation to text shown in the screen.

    H – Go to the first line of current screen.
    M – Go to the middle line of current screen.
    L – Go to the last line of current screen.
    ctrl+f – Jump forward one full screen.
    ctrl+b – Jump backwards one full screen
    ctrl+d – Jump forward (down) a half screen
    ctrl+u – Jump back (up) one half screen

3. Vim Special Navigation

You may want to do some special navigation inside a file, which are:

    N% – Go to the Nth percentage line of the file.
    NG – Go to the Nth line of the file.
    G – Go to the end of the file.
    `” – Go to the position where you were in NORMAL MODE while last closing the file.
    `^ – Go to the position where you were in INSERT MODE while last closing the file.
    g – Go to the beginning of the file.

4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:

    e – go to the end of the current word.
    E – go to the end of the current WORD.
    b – go to the previous (before) word.
    B – go to the previous (before) WORD.
    w – go to the next word.
    W – go to the next WORD.

WORD – WORD consists of a sequence of non-blank characters, separated with white space.
word – word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

    192.168.1.1 – single WORD
    192.168.1.1 – seven words.

5. Vim Paragraph Navigation

    { – Go to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph beginnings.
    } – Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.

6. Vim Search Navigation

    /i – Search for a pattern which will you take you to the next occurrence of it.
    ?i – Search for a pattern which will you take you to the previous occurrence of it.
    * – Go to the next occurrence of the current word under the cursor.
    # – Go to the previous occurrence of the current word under the cursor.

7. Vim Code Navigation

    % – Go to the matching braces, or parenthesis inside code.

8. Vim Navigation from Command Line

    Vim +N filename: Go to the Nth line of the file after opening it.

Code: [Select]
vim +10 /etc/passwd
Vim +/pattern filename
: Go to the particular pattern’s line inside the file, first occurrence from first. In the following example, it will open the README file and jump to the first occurrence of the word “install”.

Code: [Select]
vim +/install README
Vim +?patten filename: Go to the particular pattern’s line inside the file, first occurrence from last. In the following example, it will open the README file and jump to the last occurrence of the word “bug”.

Code: [Select]
vim +?bug README
Hope this article was helpful to all.

Thank you!
52
General Linux / How to Set Up SSH Keys on Debian 9
« Last post by alext on September 01, 2018, 11:24:56 am »
SSH, or secure shell, is an encrypted protocol used to administer and communicate with servers. When working with a Debian server, chances are you will spend most of your time in a terminal session connected to your server through SSH.

In this guide, we'll focus on setting up SSH keys for a vanilla Debian 9 installation. SSH keys provide an easy, secure way of logging into your server and are recommended for all users.
Step 1 — Create the RSA Key Pair

The first step is to create a key pair on the client machine (usually your computer):
Code: [Select]
ssh-keygenBy default ssh-keygen will create a 2048-bit RSA key pair, which is secure enough for most use cases (you may optionally pass in the -b 4096 flag to create a larger 4096-bit key).

After entering the command, you should see the following output:

Code: [Select]
Output
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):

Press enter to save the key pair into the .ssh/ subdirectory in your home directory, or specify an alternate path.

If you had previously generated an SSH key pair, you may see the following prompt:

Code: [Select]
Output
/home/your_home/.ssh/id_rsa already exists.
Overwrite (y/n)?

If you choose to overwrite the key on disk, you will not be able to authenticate using the previous key anymore. Be very careful when selecting yes, as this is a destructive process that cannot be reversed.

You should then see the following prompt:

Code: [Select]
Output
Enter passphrase (empty for no passphrase):

Here you optionally may enter a secure passphrase, which is highly recommended. A passphrase adds an additional layer of security to prevent unauthorized users from logging in. To learn more about security, consult our tutorial on How To Configure SSH Key-Based Authentication on a Linux Server.

You should then see the following output:

Code: [Select]
Output
Your identification has been saved in /your_home/.ssh/id_rsa.
Your public key has been saved in /your_home/.ssh/id_rsa.pub.
The key fingerprint is:
a9:49:2e:2a:5e:33:3e:a9:de:4e:77:11:58:b6:90:26 username@remote_host
The key's randomart image is:
+--[ RSA 2048]----+
|     ..o         |
|   E o= .        |
|    o. o         |
|        ..       |
|      ..S        |
|     o o.        |
|   =o.+.         |
|. =++..          |
|o=++.            |
+-----------------+
You now have a public and private key that you can use to authenticate. The next step is to place the public key on your server so that you can use SSH-key-based authentication to log in.
Step 2 — Copy the Public Key to Debian Server

The quickest way to copy your public key to the Debian host is to use a utility called ssh-copy-id. Due to its simplicity, this method is highly recommended if available. If you do not have ssh-copy-id available to you on your client machine, you may use one of the two alternate methods provided in this section (copying via password-based SSH, or manually copying the key).
Copying Public Key Using ssh-copy-id

The ssh-copy-id tool is included by default in many operating systems, so you may have it available on your local system. For this method to work, you must already have password-based SSH access to your server.

To use the utility, you simply need to specify the remote host that you would like to connect to and the user account that you have password SSH access to. This is the account to which your public SSH key will be copied.

The syntax is:

   
Code: [Select]
ssh-copy-id username@remote_host
You may see the following message:

Code: [Select]
Output
The authenticity of host '203.0.113.1 (203.0.113.1)' can't be established.
ECDSA key fingerprint is fd:fd:d4:f9:77:fe:73:84:e1:55:00:ad:d6:6d:22:fe.
Are you sure you want to continue connecting (yes/no)? yes

This means that your local computer does not recognize the remote host. This will happen the first time you connect to a new host. Type "yes" and press ENTER to continue.

Next, the utility will scan your local account for the id_rsa.pub key that we created earlier. When it finds the key, it will prompt you for the password of the remote user's account:

Code: [Select]
Output
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
username@203.0.113.1's password:

Type in the password (your typing will not be displayed for security purposes) and press ENTER. The utility will connect to the account on the remote host using the password you provided. It will then copy the contents of your ~/.ssh/id_rsa.pub key into a file in the remote account's home ~/.ssh directory called authorized_keys.

You should see the following output:

Code: [Select]
Output
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'username@203.0.113.1'"
and check to make sure that only the key(s) you wanted were added.

At this point, your id_rsa.pub key has been uploaded to the remote account. You can continue on to Step 3.
Copying Public Key Using SSH

If you do not have ssh-copy-id available, but you have password-based SSH access to an account on your server, you can upload your keys using a conventional SSH method.

We can do this by using the cat command to read the contents of the public SSH key on our local computer and piping that through an SSH connection to the remote server.

On the other side, we can make sure that the ~/.ssh directory exists and has the correct permissions under the account we’re using.

We can then output the content we piped over into a file called authorized_keys within this directory. We’ll use the >> redirect symbol to append the content instead of overwriting it. This will let us add keys without destroying previously added keys.

The full command looks like this:

   
Code: [Select]
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
You may see the following message:

Code: [Select]
Output
The authenticity of host '203.0.113.1 (203.0.113.1)' can't be established.
ECDSA key fingerprint is fd:fd:d4:f9:77:fe:73:84:e1:55:00:ad:d6:6d:22:fe.
Are you sure you want to continue connecting (yes/no)? yes

This means that your local computer does not recognize the remote host. This will happen the first time you connect to a new host. Type "yes" and press ENTER to continue.

Afterwards, you should be prompted to enter the remote user account password:

Code: [Select]
Output
username@203.0.113.1's password:

After entering your password, the content of your id_rsa.pub key will be copied to the end of the authorized_keys file of the remote user's account. Continue on to Step 3 if this was successful.
Copying Public Key Manually

If you do not have password-based SSH access to your server available, you will have to complete the above process manually.

We will manually append the content of your id_rsa.pub file to the ~/.ssh/authorized_keys file on your remote machine.

To display the content of your id_rsa.pub key, type this into your local computer:
Code: [Select]
    cat ~/.ssh/id_rsa.pub
You will see the key's content, which should look something like this:

Code: [Select]
Output
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqql6MzstZYh1TmWWv11q5O3pISj2ZFl9HgH1JLknLLx44+tXfJ7mIrKNxOOwxIxvcBF8PXSYvobFYEZjGIVCEAjrUzLiIxbyCoxVyle7Q+bqgZ8SeeM8wzytsY+dVGcBxF6N4JS+zVk5eMcV385gG3Y6ON3EG112n6d+SMXY0OEBIcO6x+PnUSGHrSgpBgX7Ks1r7xqFa7heJLLt2wWwkARptX7udSq05paBhcpB0pHtA1Rfz3K2B+ZVIpSDfki9UVKzT8JUmwW6NNzSgxUfQHGwnW7kj4jp4AT0VZk3ADw497M2G/12N0PPB5CnhHf7ovgy6nL1ikrygTKRFmNZISvAcywB9GVqNAVE+ZHDSCuURNsAInVzgYo9xgJDW8wUw2o8U77+xiFxgI5QSZX3Iq7YLMgeksaO4rBJEa54k8m5wEiEE1nUhLuJ0X/vh2xPff6SQ1BL/zkOhvJCACK6Vb15mDOeCSq54Cr7kvS46itMosi/uS66+PujOO+xt/2FWYepz6ZlN70bRly57Q06J+ZJoc9FfBCbCyYH7U/ASsmY095ywPsBo1XQ9PqhnN1/YOorJ068foQDNVpm146mUpILVxmq41Cj55YKHEazXGsdBIbXWhcrRf4G2fJLRcGUr9q8/lERo9oxRm5JFX6TCmj6kmiFqv+Ow9gI0x8GvaQ== demo@test
Access your remote host using whichever method you have available.

Once you have access to your account on the remote server, you should make sure the ~/.ssh directory exists. This command will create the directory if necessary, or do nothing if it already exists:

   
Code: [Select]
mkdir -p ~/.ssh
Now, you can create or modify the authorized_keys file within this directory. You can add the contents of your id_rsa.pub file to the end of the authorized_keys file, creating it if necessary, using this command:

   
Code: [Select]
echo public_key_string >> ~/.ssh/authorized_keys
In the above command, substitute the public_key_string with the output from the cat ~/.ssh/id_rsa.pub command that you executed on your local system. It should start with ssh-rsa AAAA....

Finally, we’ll ensure that the ~/.ssh directory and authorized_keys file have the appropriate permissions set:

   
Code: [Select]
chmod -R go= ~/.ssh
This recursively removes all “group” and “other” permissions for the ~/.ssh/ directory.

If you’re using the root account to set up keys for a user account, it’s also important that the ~/.ssh directory belongs to the user and not to root:

   
Code: [Select]
chown -R sammy:sammy ~/.ssh
In this tutorial our user is named sammy but you should substitute the appropriate username into the above command.

We can now attempt passwordless authentication with our Debian server.
Step 3 — Authenticate to Debian Server Using SSH Keys

If you have successfully completed one of the procedures above, you should be able to log into the remote host without the remote account's password.

The basic process is the same:

   
Code: [Select]
ssh username@remote_host
If this is your first time connecting to this host (if you used the last method above), you may see something like this:

Code: [Select]
Output
The authenticity of host '203.0.113.1 (203.0.113.1)' can't be established.
ECDSA key fingerprint is fd:fd:d4:f9:77:fe:73:84:e1:55:00:ad:d6:6d:22:fe.
Are you sure you want to continue connecting (yes/no)? yes
This means that your local computer does not recognize the remote host. Type "yes" and then press ENTER to continue.

If you did not supply a passphrase for your private key, you will be logged in immediately. If you supplied a passphrase for the private key when you created the key, you will be prompted to enter it now (note that your keystrokes will not display in the terminal session for security). After authenticating, a new shell session should open for you with the configured account on the Debian server.

If key-based authentication was successful, continue on to learn how to further secure your system by disabling password authentication.
Step 4 — Disable Password Authentication on your Server

If you were able to log into your account using SSH without a password, you have successfully configured SSH-key-based authentication to your account. However, your password-based authentication mechanism is still active, meaning that your server is still exposed to brute-force attacks.

Before completing the steps in this section, make sure that you either have SSH-key-based authentication configured for the root account on this server, or preferably, that you have SSH-key-based authentication configured for a non-root account on this server with sudo privileges. This step will lock down password-based logins, so ensuring that you will still be able to get administrative access is crucial.

Once you've confirmed that your remote account has administrative privileges, log into your remote server with SSH keys, either as root or with an account with sudo privileges. Then, open up the SSH daemon's configuration file:

   
Code: [Select]
sudo nano /etc/ssh/sshd_config
Inside the file, search for a directive called PasswordAuthentication. This may be commented out. Uncomment the line and set the value to "no". This will disable your ability to log in via SSH using account passwords:
/etc/ssh/sshd_config

Code: [Select]
...
PasswordAuthentication no
...
Save and close the file when you are finished by pressing CTRL + X, then Y to confirm saving the file, and finally ENTER to exit nano. To actually implement these changes, we need to restart the sshd service:

   
Code: [Select]
sudo systemctl restart ssh
As a precaution, open up a new terminal window and test that the SSH service is functioning correctly before closing this session:

   
Code: [Select]
ssh username@remote_host
Once you have verified your SSH service, you can safely close all current server sessions.

The SSH daemon on your Debian server now only responds to SSH keys. Password-based authentication has successfully been disabled.
Conclusion

You should now have SSH-key-based authentication configured on your server, allowing you to sign in without providing an account password.
53
General Linux / How To Install Wine 3.0 on CentOS, RHEL and Fedora
« Last post by vichithrakumart on September 01, 2018, 11:02:58 am »
Install 'Development  Tools' using yum

Code: [Select]
#yum groupinstall 'Development Tools'
#yum install libX11-devel freetype-devel zlib-devel libxcb-devel \
      libxslt-devel libgcrypt-devel libxml2-devel gnutls-devel \
      libpng-devel libjpeg-turbo-devel libtiff-devel gstreamer-devel \
      dbus-devel fontconfig-devel

Install Wine from source

Code: [Select]
# cd /usr/src
# wget http://dl.winehq.org/wine/source/3.0/wine-3.0.tar.xz
# tar -Jxf wine-3.0.tar.xz
# cd wine-3.0

Configure it

Code: [Select]
# ./configure
Compile and install the source code

Code: [Select]
# make
# make install
54
General Linux / Install OPCache to Improve PHP Performance in CentOS 7
« Last post by vyshnavk on August 22, 2018, 09:34:54 pm »
PHP is one of the most popular programming language for developing applications, you will find it on every web hosting server. The most popular Content Management Systems (CMSs) are written in PHP, such as WordPress, Drupal, and Joomla.

One of the many reasons why PHP is well known out there is because it has numerous extensions in its default distribution, an example is OPcahce.

What is Opcache and How Does it Work?

Originally known as Zend Optimizer+, Opcache (introduced in PHP 5.5.0) is a powerful PHP extension built to enhance PHP performance thus boosting overall application performance. It is available as an extension through PECL for PHP versions 5.2, 5.3 and 5.4. It works by storing pre-compiled script byte-code in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

In this article, we will explain how to install and configure OPcache in CentOS 7 for a specific PHP version.

Install Opcache PHP Extension in CentOS 7

1. First start by installing the EPEL repository and followed by the REMI repository on your system, as follows.

Code: [Select]
# yum update && yum install epel-release
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm 

2. Next, you need to install yum-utils, a collection of utilities to extend yum’s default features; they help you manage yum repositories as well as packages without any manual configuration and more.

Code: [Select]
# yum install yum-utils
3. Once you have yum-utils installed, use yum-config-manager to enable Remi repository as the default repository for installing different PHP versions and modules.

Code: [Select]
# yum-config-manager --enable remi-php55 #For PHP 5.5
# yum-config-manager --enable remi-php56 #For PHP 5.6
# yum-config-manager --enable remi-php70 #For PHP 7.0
# yum-config-manager --enable remi-php71 #For PHP 7.1
# yum-config-manager --enable remi-php72 #For PHP 7.2

4. Now install Opcache extension and verify your PHP version to confirm that it has Opcache extension installed using following commands.

Code: [Select]
# yum install php-opcache
# php -v



Configure Opcache PHP Extension in CentOS 7

5. Next, configure OPcache by editing the /etc/php.d/10-opcache.ini (or /etc/php.d/10-opcache.ini) file using your favorite editor.

Code: [Select]
# vim /etc/php.d/10-opcache.ini
The following settings should get you started with using OPcache and are generally recommended as good performance. You can enable a configuration by uncommenting it.

Code: [Select]
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

6. Finally, restart your web server for Opcache to start working.

Code: [Select]
# systemctl restart nginx
OR
# systemctl restart httpd

That’s all! Opcache is a PHP extension built to improve PHP performance. In this article, we have explained how to install and configure OPcache in CentOS7



55
Plesk / Error in MySQL log files: Incorrect definition of table mysql.event
« Last post by vichithrakumart on August 12, 2018, 04:29:04 pm »
The following error can be found in /var/log/mysql.log:

Code: [Select]
[ERROR] Incorrect definition of table mysql.event: expected column 'sql_mode' at position 14 to have type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH'), found type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_A
MySQL was replaced with MariaDB some time ago or MySQL/MariaDB was upgraded to a higher version.

During the upgrade of MySQL/MariaDB, mysql_upgrade command was not executed or was executed with errors.

To resolve the issue

1. Log in to the server via SSH

2. create a backup of /var/lib/mysql

Code: [Select]
# cp -a /var/lib/mysql/ /var/lib/mysql_backup/
3. Start mysql_upgrade with admin user credentials:

Code: [Select]
# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin
4. Restart MySQL service:

Code: [Select]
# service mysql restart
56
Plesk / Unable to start MySQL because of lack of RAM: mysqld dead but subsys locked
« Last post by vichithrakumart on August 12, 2018, 04:07:23 pm »
The following error is shown when querying the status of the service:

Code: [Select]
# service mysqld status
mysqld dead but subsys locked

it is required to remove /var/lock/subsys/mysqld file, free up some memory and start MySQL.

1. Log into the server via SSH

2. Remove /var/lock/subsys/mysqld file:

Code: [Select]
# rm -f /var/lock/subsys/mysqld
3. Check the amount of free memory with free -m command. In case there is more then 200M free, skip this step. In case amount of free memory is low, kill processes that consumes most of the memory. For example, stop the Apache temporary:

Code: [Select]
# service httpd stop
4. Try to start MySQL:

Code: [Select]
# service mysqld start
5. In case Apache is stopped on step 3, start it back:

Code: [Select]
# service httpd start
57
Plesk / How to assign multiple database users to another database?
« Last post by vichithrakumart on August 12, 2018, 03:53:08 pm »
You can use database utility to add the user to the existing database:

Code: [Select]
# plesk bin database --update <db_name> -add_user <db_user> -passwd <password>
Code: [Select]
db_name1 db_user1 password1
db_name2 db_user2 password2
db_name3 db_user3 password3


The 1st column is database name on the database server where it is required to add database user.
The 2nd column is a name of a database user.
The 3rd column is a password of a database user.

After this, connect to the server via SSH and run the utility in a loop taking the data from /root/db_user.list file:
Code: [Select]
# cat /root/db_user.list | while read var1 var2 var3 ; do plesk bin database --update $var1 -add_user $var2 -passwd $var3 ; echo user $var2 - success; done
   


58
Plesk / How to upgrade MariaDB 10.0 to 10.1 on CentOS 7
« Last post by vichithrakumart on August 12, 2018, 01:13:35 pm »
1. Connect the server via ssh
2. Create a back up all the databases with the following command

Code: [Select]
# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -u admin --all-databases --routines --triggers > /tmp/all-databases.sql
3. Create a databases directory in a separate folder

Code: [Select]
# cp -a /var/lib/mysql/ /var/lib/mysql_backup
4. Configure the repository by modifying the /etc/yum.repos.d/MariaDB.repo

Code: [Select]
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1

5. Run yum update to update the MariaDB packages

6. Remove the old Mariadb package without dependencies

Code: [Select]
# rpm -e --nodeps MariaDB-server-10.0.35-1.el7.centos.x86_64
7. Install MariaDB-server package v.10.1

Code: [Select]
# yum install MariaDB-server
8. Start the MariaDB service

Code: [Select]
#service mariadb start
9. Upgrade MySQL databases

Code: [Select]
# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin
10. Restart MySQL service

Code: [Select]
# service mariadb restart
11. Update the package version by running

Code: [Select]
# plesk sbin packagemng -sdf
12. Remove the mysql init script and reload the systemctl daemon

Code: [Select]
# rm /etc/init.d/mysql
# systemctl daemon-reload

13. Check the mariadb status

Code: [Select]
#service mariadb status



59
General Linux / How to create custom commands
« Last post by vichithrakumart on August 12, 2018, 12:05:39 pm »
1. Create a directory bin under your home directory
2. Update your path variable to include this bin directory. Put this in .profile or .bash_profle file to make it permanent.

Code: [Select]
export PATH=$PATH":$HOME/bin"
3. Create a script on this directory and give execution permission

4. Reload .profile or .bash_profile

Code: [Select]
$ . ~/.bash_profile
5. You can simply type the script file name to execute the command
60
General Linux / LFCS sed Command !!!!!!!
« Last post by alext on August 11, 2018, 04:53:22 pm »
Another useful command for the Linux Foundation Certified SysAdmin (LFCS) is the 'sed' Command. The initials stand for 'Streaming EDitor'.

The 'sed' Command is an editor that edits the file as a stream. To stream a file is to pass it from another command using pipes (> or |) or load it directly into 'sed'.

The command works like any other editor except that the file is not displayed and allowed to be edited visually. Commands are passed to 'sed' to manipulate the stream.

With 'sed' there are five basic things which can be done. Of course, with 'sed' being so powerful there are more advanced functions, but you only need to concentrate on the basic five. The five types of functionality are as follows:

    Search
    Replace
    Delete
    Adding
    Change/Transform

Before getting into the command parameters we need to look over the basic syntax.

Syntax

The syntax for the 'sed' command is:

Code: [Select]
sed [options] commands [file-to-edit]
The options will be covered in this article in the appropriate sections. The commands are the search and replacement patterns which can be Regex Expressions. Read on to see how 'sed' works and learn the basic commands. As I mentioned before, 'sed' is a very powerful tool and has more options available than I will cover in the article.

Example File

If you open a Terminal you can create a file to be used for the 'sed' examples. Perform the following commands:

cd ~
grep --help >grephelp.txt

You should now have a file named 'grephelp.txt' in your HOME folder. The contents of the file are the help instructions for the command 'grep'.

Search

Searching for specific strings is a common ability of editors and performing searches in 'sed' is no exception.

Searches can be performed to find a string in a file. Let's look at a basic search.

If we wanted to search through our example file for the word 'PATTERN' we would use the command and see the results in Figure 1:
Code: [Select]
sed -n 's/PATTERN/PATTERN/p' grephelp.txtThe parameter '-n' is used to suppress the printing of each line automatically. These lines include lines which do not include the search pattern. By using the '-n' the lines with a matching result will be displayed. Every line which is streamed into 'sed' will be printed to the standard out (stdout). If you run the above command without the '-n' option you will have a line for every line in the original file as well as a duplicate line for each match.

The file name to search is 'grephelp.txt' which we created in the 'Example File' section.

The portion left is 's/PATTERN/PATTERN/p'. There are basically four sections to this section. The first section 's' specifies to perform a substitution, or a search and replace.

The second and third part of the remaining portion are the patterns. The first is the pattern to search for and the last is the pattern to replace the matching string within the stream. In this case we are finding the string 'PATTERN' and replacing it with 'PATTERN'. By finding and replacing the same string we are not changing the file at all, even on the screen.

The last command is 'p'. The 'p' command specifies to print the new line after the substitution is made. Of course, there is no change since the substitution is the same string. Since we are suppressing printing lines with ‘-n’ parameter only the changed lines will be printed with the ‘p’ command.

The whole command allows us to perform a search and see the matching results.

Replace

When searching for specific strings you may want to replace the matching string with a new one. Replacing strings with another is very common.
In this instance, the string 'PATTERN' is changed to 'Pattern' and displayed. If you view the file with the command 'cat grephelp.txt' you will see that the file has not changed. The change was made only to the output on the screen. You could pipe the output to another file with the command:

Code: [Select]
sed 's/PATTERN/Pattern/' grephelp.txt > grephelp1.txt
A new file called 'grephelp1.txt' would now exist which held the changed file. If the 'p' was left in as the fourth option then the problem is that each line that had a string substituted would exist twice in the file. We also drop the '-n' parameter to allow all the lines to print.

Another way to replace the string with the same string is to use the ‘&’ symbol to represent the search string. For example, the command ‘s/PATTERN/&/p’ would be the same. We can add to the string, such as adding an ‘S’, with the command ‘s/PATTERN/&S/p’.

What if we wish to replace only a certain pattern in each line? It is possible to specify the specific occurrence of a match to replace. Of course, the replacement will be a specific numbered occurrence on each line. For example, there are a lot of dashes on the sample file. Some lines have at least two dashes so we can replace the second dash in each line with another character. The command to replace the second dash (-) in each line with an asterisk (*) would be:

Code: [Select]
sed 's/-/*/2' grephelp.txt
Here, we are performing a substitution with the initial ‘s’. The character ‘-’ is replaced with the ‘*’. The ‘2’ shows we are wanting to replace the second instance of the ‘-’ on each line if it exists. A sample result is shown in Figure 3. If we left out the command ‘2’ then the first occurrence of a dash is replaced. Not every dash of a line is replaced only the first one.

If you want to search and replace all dashes on a line with an asterisk, use the ‘g’ command:

Code: [Select]
sed 's/-/*/g' grephelp.txt
Commands can also be combined. Let’s say you want to change all dashes starting at the second occurrence to the end, the command would be:

Code: [Select]
sed 's/-/*/2g' grephelp.txt
Now every dash from the second to the last on every line is replaced with an asterisk.

Delete

Many times during a search you may want to remove the search string completely.

For instance, if you wanted to remove all dashes from the file you could use the command:

Code: [Select]
sed ‘s/-//g’ grephelp.txt
The replacement string is left as a blank so the matching string is removed or deleted.

Adding

When a match is found you can add a line of specific text to make the line stand out for viewing or printing.

If you want the new line to be inserted after the match use the ‘a’ command followed by the string for the new line. Also include the string to match. For example, we can find a ‘--’ and add a line after the matched line. The string on the added line will be ‘double dash before this line’.

sed '/--/ a "double dash before this line"' grephelp.txt

If you want to place the line before the line containing the matched string use the ‘i’ command as follows:
Code: [Select]
sed '/--/ i "double dash after this line"' grephelp.txt
Change/Transform

If a line needs to be changed or transformed you can use the command ‘c’.

Let’s say we have a document which has some private information and we need to change any line which contains a specific string. The ‘c’ command will change the whole line and not just the search string.

Let’s say in our example file we want to block out every line which contains the word ‘PATTERN’. The changed line will read ‘This line is Top Secret’. The command is:

Code: [Select]
sed ‘/PATTERN/ c This line is Top Secret’ grephelp.txt
A Transformation can be performed to change case of specific letters. For instance, we can change all lower-case ‘a’ to uppercase ‘A’ with the command ‘y’ as follows:

Code: [Select]
sed ‘y/a/A/’ grephelp.txt
Multiple letters can be specified such as ‘abdg’ as in the following command:

Code: [Select]
sed ‘y/abdg/ABDG/’ grephelp.txt
Make sure the second set of letters are in the same order as the first or they can be replaced and transformed. For example, the string ‘y/a/D/’ would replace all lower-case ‘a’ with an upper-case ‘D’.

In-place change

If you actually want to make changes to the file you are using, use the ‘-i’ option.

For example, to change the word ‘PATTERN’ to ‘Pattern’ and have the changes made to the file, the command would be:

Code: [Select]
sed -i 's/PATTERN/Pattern/' grephelp.txt
The file ‘grephelp.txt’ will now be changed. The ‘-i’ option can be used with any of the above commands to change the original file content.

Practice with these commands and make sure you understand them. The ‘sed’ command is very powerful.

Pages: 1 ... 4 5 [6] 7 8 ... 10