Posts

Showing posts from June, 2018

Split a string in shell and get the last field

Image
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 . Introduction 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 shell and get the last field one_path="/www/huu/phan/com/xyz" last_slash=-1 for (( i=0; i < ${#one_path}; i++)); do         if [ ${one_path:$i:1} == '/' ]         then                 last_slash=$i;         fi done new_path=${one_path:0:$last_slash} last_field=$(basename $new_path) echo "Old path: $one_path" echo "New path: $new_path" echo "Last field of $new_path:  $last_field" The display as picture below:

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 [email protected] . The command line as below running su - zimbra . Now, let's start! Lock and Unlock zimbra account Step 1: Checking status account [email protected] 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 [email protected] $ zmprov ma [email protected] zimbraAccountStatus locked The display as picture below: To check account status after locked Step 3: To Unlock zimbra account [email protected] $ zmprov ma [email protected] 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 number