Posts

Step-by-Step: Split a string in shell and get the last field

Image
Introduction String manipulation is a crucial skill in shell scripting. One common task is to split a string and retrieve specific fields, such as the last one. This can be useful for various purposes, such as parsing file paths, URLs, or command outputs. In this guide, we'll explore different methods to split a string and get the last field in shell scripting, starting from basic techniques and moving towards more advanced examples. How to split a string in shell and get the last field. in this tutorial, i written a small program use bash script split string /www/huu/phan/com/xyz to new path /www/huu/phan/com and last field of new path /www/huu/phan/com is com . How to Split a string in shell and get the last field Input: one_path is /www/huu/phan/com/xyz Output: new_path is  /www/huu/phan/com last_field of new_path is com My bash shell as below: #!/bin/bash ############### # # Author: HuuPV # My blog: www.huuphan.com # ############### # How to split a string in shel...

Lock and Unlock zimbra account from command line

Image
How to Lock and Unlock zimbra account from command line. some account sending email spam, you are administrator to need lock account from command line. To login your Mailbox system. To perform some command below to lock and unlock zimbra account. For example, I will lock and unlock account huupv02@mail.huuphan.com . The command line as below running su - zimbra . Now, let's start! Lock and Unlock zimbra account Step 1: Checking status account huupv02@mail.huuphan.com as below: $ zmprov ga huupv02mail.huuphan.com | grep zimbraAccountStatus The display as below: Another command to check status account with zmaccts as below: Step 2: To Lock zimbra account huupv02@mail.huuphan.com $ zmprov ma huupv02@mail.huuphan.com zimbraAccountStatus locked The display as picture below: To check account status after locked Step 3: To Unlock zimbra account huupv02@mail.huuphan.com $ zmprov ma huupv02@mail.huuphan.com zimbraAccountStatus active The display as picture belo...

Linux diff command

Image
In this tutorial, I use diff command output on screen. How to compare different line by line in  files. How to compare side by side, color , output do not output common lines with diff command. What diff command work? compare files line by line For example my topic, I compare line by line in 2 file: file1.txt and file2.txt The content file1.txt file [huupv@huupv huuphan.com]$ cat file1.txt <####################################> author: huupv My Blog: www.huuphan.com Hello everbody! <####################################> The content file2.txt file [huupv@huupv huuphan.com]$ cat file2.txt <####################################> author: huupv My Blog: www.devopsrole.com Hello everbody! <####################################> The default compare line by line with diff comand [huupv@huupv huuphan.com]$ diff file1.txt file2.txt The output as below: 3c3 < My Blog: www.huuphan.com --- > My Blog: www.devopsrole.com The output nu...

How to Configure Postfix only allow whitelisted Recipient Domain

Image
Introduction Learn how to configure Postfix to only allow emails to be sent to whitelisted recipient domains. This step-by-step guide includes user data for testing and minimizes the risk of sending emails to unwanted recipients. In today's digital world, securing your email server is crucial. One effective method to enhance email security is by configuring Postfix to only allow whitelisted recipient domains. This guide will walk you through the process, providing clear examples and detailed steps to help you set up and test this configuration in your environment. In this tutorial, How to Configure " Postfix only allow whitelisted Recipient Domain ". We test environment with user data. To minimize the risk of sending to unwanted email recipients. Configuring Postfix to Allow Only Whitelisted Recipient Domains Step 1: Modify the main.cf File To begin, you need to modify the Postfix main configuration file ( main.cf ) to specify the recipient restrictions. Open the m...

Bash script arguments from a file content:Mastering Shell Scripting

Image
Introduction Learn how to change string content of a file using bash script arguments. This guide provides detailed steps and examples, from default values to custom arguments. Master shell scripting to dynamically update file content efficiently. Bash scripting is a versatile and powerful tool for automating tasks and managing system operations. One common requirement is changing specific string content in a file using arguments passed to a script. This guide will demonstrate how to achieve this with a bash script, covering both default values and custom arguments. By following this tutorial, you will enhance your scripting skills and be able to dynamically update file content efficiently. In this tutorial, how to change string content of file as arguments. I written  Bash script arguments from a file content as below: What is Bash Scripting? Bash scripting involves writing a series of commands in a text file to be executed by the Bash shell . It is widely used for automating repe...

Bash script argument default value and takes optional input arguments

Image
Introduction Learn how to handle default values for arguments and optional input arguments in Bash scripts. This comprehensive guide covers everything from basic to advanced examples, ensuring you can write efficient and flexible scripts. Bash scripting is a powerful tool for automating tasks and managing systems. One essential aspect of writing efficient Bash scripts is handling arguments and providing default values. This ensures that your scripts can handle various scenarios without requiring mandatory inputs every time. In this article, we will explore how to handle default values for arguments and optional input arguments in Bash scripts, from basic to advanced examples. Understanding Bash Script Arguments What are Bash Script Arguments? Bash script arguments are parameters passed to a script at runtime. These arguments are used to provide input data to the script, making it dynamic and versatile. In Bash, arguments are accessed using the $ symbol followed by their position (e.g....

How to NGINX Solution for Apache ProxyPassReverse

Image
Introduction When managing web servers, it's common to encounter the need to reverse proxy through different web servers. Apache's mod_proxy module offers ProxyPass and ProxyPassReverse directives to handle these tasks. However, NGINX can be used as an alternative to Apache for reverse proxy needs due to its performance and configuration simplicity. This article explores how to use NGINX to achieve similar functionality to Apache's ProxyPassReverse. NGINX Solution for Apache ProxyPassReverse Understanding Apache’s ProxyPassReverse The ProxyPassReverse directive in Apache adjusts the URLs in the HTTP headers sent from a reverse proxy. This is essential for maintaining session consistency when the backend server redirects responses. Apache configure <VirtualHost myhost:8888>     ServerName myhost     DocumentRoot /path/to/myapp/public     ProxyPass / http://myapp:8080/     ProxyPassReverse / http://myapp:8080/ ...

Openssl libssl.so.1.1 not found solve problem

How to solve problem Openssl libssl.so.1.1 not found on your system such as centos, ubuntu. Installing openssl missing depens libssl.so.1.1 not found and libcrypto.so.1.1 not found. Openssl libssl.so.1.1 not found problem as below: [huupv@huupv ~]$ ldd /usr/bin/openssl     linux-vdso.so.1 (0x00007ffe185e6000)     libssl.so.1.1 => => not found     libcrypto.so.1.1 => => not found     libz.so.1 => /lib64/libz.so.1 (0x00007fc3ca6f4000)     libdl.so.2 => /lib64/libdl.so.2 (0x00007fc3ca4f0000)     libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc3ca2d2000)     libc.so.6 => /lib64/libc.so.6 (0x00007fc3c9f1c000)     /lib64/ld-linux-x86-64.so.2 (0x00007fc3cb2a1000) Openssl libssl.so.1.1 not found solve problem sudo ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 sudo ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcr...

Mastering the sed command regex example for Linux

Image
Introduction The sed command in Linux is a powerful stream editor that allows users to filter and transform text in various ways. Whether you're working on system administration tasks or programming scripts, mastering sed can significantly improve your efficiency. In this tutorial, we will explore how to use sed with regex to manipulate lines within a file, focusing on printing lines from one point to another. This guide will help you understand the nuances of sed and its regex capabilities, ensuring you can handle text processing with ease. What is the sed Command? The sed (stream editor) command in Linux is used to perform basic text transformations on an input stream (a file or input from a pipeline). It is commonly used for text substitution, but it also allows you to select and manipulate lines, delete text, and more, using regex (regular expressions). Key Features of sed Text Substitution : Replace occurrences of a pattern with a specific string. Line Selection : Selec...

Configure Postfix to use Gmail as a Mail Relay

In this tutorial, I setup and Configure Postfix to use Gmail as a Mail Relay with 587 port. OS : Centos User : root Install postfix yum install postfix mailx cyrus-sasl cyrus-sasl-plain To configure postfix to use Gmail as a Mail Relay vi /etc/postfix/main.cf Add or modify the following as below: #To use smpt gmail with 587 port relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt smtp_tls_security_level = encrypt # Location of CA certificates smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt To configure Gmail authentication vi /etc/postfix/sasl_passwd Add the line as below: [smtp.gmail.com]:587    username@gmail.com:password Running commands as below: chmod 600 /etc/postfix/sasl_passwd chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db postmap /etc/po...