Install git from source Centos 6

In this tutorial, How to install Git from source Centos 6. Git the essential for DevOps Roles. 

To install Git from source on CentOS 6, you can follow these steps:

Install git from source Centos

Update System Packages:

Install “Development Tools” for Centos 6.

$ sudo yum -y groupinstall "Development Tools"

To install the package prepare git

$ sudo yum install -y gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel curl-devel expat-devel openssl-devel gcc perl-ExtUtils-MakeMaker

Downloading Git from source link the latest here. I use git version 2.18.

$ wget https://www.kernel.org/pub/software/scm/git/git-2.18.0.tar.gz

Decompress and install Git from the source

$ tar xzf git-2.18.0.tar.gz
$ cd git-2.18.0
$ make configure
$ ./configure
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
$ git --version

You should see the Git version displayed if the installation was successful.

Conclusion

Through the article, you can “install Git from source Centos 6” as above. You can start using Git by executing Git commands in the terminal. I hope will this your helpful. Thank you for reading the DevopsRoles page!

RPM query installed packages in Centos RHEL and Fedora

In this tutorial, I using the rpm command to query lists the packages installed on the system. How do I use “rpm query installed packages in Centos, RHEL, and Fedora“. Linux the essential for DevOps Roles.

RPM query installed packages

List of the only package installed your system.

$ rpm -qa --qf "%{NAME}\n"

Example, List of the package installed on “Server A”. After then, How to install the package from “Server A” for “Server B”

Server A $ rpm -qa --qf "%{NAME}\n" > packaged.list
Server B # xargs yum -y < packaged.list

Display the package names, versions and releases with this command

[huupv@huupv devopsroles]$ rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n'

The screen output terminal as below

Conclusion

Thought the article, How to use “RPM query installed packages in Centos RHEL and Fedora” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

bad interpreter: /bin/sh^M: no such file or directory solve problem

In this tutorial, How to solve bad interpreter when running the shell exit with “bad interpreter: /bin/sh^M: no such file or directory“. I will be using three methods. Linux the essential for DevOps Roles.

bad interpreter: /bin/sh^M: no such file or directory fixed

Method 1: Using vim editor

Open vim and insert the following command

:set fileformat=unix
:x

Or

:set ff=unix
:x

Method 2: Using sed command

[huupv@huupv devopsroles]$ sed -i 's/\r//' FILE_NAME

Method 3: I Using dos2unix command

[huupv@huupv devopsroles]$ dos2unix FILE_NAME

Conclusion

Thought the article, You have solved the problem “bad interpreter: /bin/sh^M: no such file or directory” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Useful shell commands

In this tutorial, I will write about Useful shell commands. Tips and trick about kill process, How to remove ssh host and SCP command. Bash script the essential for DevOps Roles.

Useful shell commands

Kill Process

ps aux | grep <keyword> | grep -v grep | awk '{ print "kill -9", $2 }' | sh

For example, How to kill running Tilix process as the picture below

Kill the process Tilix

[huupv@huupv devopsroles]$ ps aux | grep tilix | grep -v grep | awk '{ print "kill -9", $2 }' | sh

How to remove ssh host

ssh-keygen -R <IP address/host_name>

SCP command

Upload to server

scp -i <ssh key private file> -r <local directory/file> <user>@<remote server>:<remote directory/file>

Download from server

scp -i <ssh key private file> -r <user>@<remote server>:<remote directory/file> <local directory/file>

Conclusion

Thought the article, How to use “Useful shell commands” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to Import Export Jobs Jenkins

Introduction

In this tutorial, How to Import Export jobs, Jenkins. It is easy to import and export Jenkins jobs and plugin when you migrate Jenkins jobs to a new server. I use Butler CLI. Jenkins the essential for DevOps Roles.

To get butler package for your system Linux. Link butler download.

Install butler

wget https://s3.us-east-1.amazonaws.com/butlercli/1.0.0/linux/butler
chmod +x butler
mv butler /usr/local/bin/

To verify the Bulter

/usr/local/bin/butler help

Import Export Jobs Jenkins

OLD SERVER

To export Jenkins plugins

/usr/local/bin/butler plugins export  --server localhost:8080  --username admin  --password admin

Butler will dump a list of plugins installed to new file “plugins.txt”

To export Jenkins jobs

/usr/local/bin/butler jobs export  --server localhost:8080  --username admin  --password admin

A new directory “jobs” will be created with every job in Jenkins. Each job it owns configure file config.xml

NEW SERVER

To import Jenkins plugins

/usr/local/bin/butler plugins import  --server localhost:8080  --username admin  --password admin

To import Jenkins jobs

/usr/local/bin/butler jobs import  --server localhost:8080  --username admin --password admin

Another method, you can refer to from StackOverflow

Conclusion

Throughout the article, you can use “Import Export Jobs Jenkins” as mentioned above. I hope this will be helpful to you. Thank you for reading the DevopsRoles page!

Bash script copy rename multiple files

In this tutorial, I am written a small program with “Bash script copy rename multiple files” on Linux. Linux the essential for DevOps Roles.

The syntax for the loop

for file in $(ls)
do
       cp $file ${file/<Pattern>/<Replacement>}; 
done

For example, I will copy and rename 2 files “foo2017-2.txt and foo2017-3.txt” into “foo2018-2.txt and foo2018-3.txt”  in “folder” folder.

[huupv@huupv devopsroles]$ pwd
/home/huupv/devopsroles
[huupv@huupv devopsroles]$ ls folder/
file.txt foo2017-1.txt foo2017-2.txt foo2017-3.txt
[huupv@huupv devopsroles]$

My Bash script copy rename multiple files

#!/bin/bash
#Only 2 copies files from the bottom and change 2017 to 2018

FOLDER=$1;
for file in $(ls $FOLDER/ | tail -n2)
do
   cp ${FOLDER}/${file} ${FOLDER}/${file/2017/2018};
done

Execute bash script

[huupv@huupv devopsroles]$ chmod +x bash_rename_files.sh
[huupv@huupv devopsroles]$ ./bash_rename_files.sh /home/huupv/devopsroles/folder

The result, after you run the bash script

[huupv@huupv devopsroles]$ ls /home/huupv/devopsroles/folder/
file.txt foo2017-1.txt foo2017-2.txt foo2017-3.txt foo2018-2.txt foo2018-3.txt
[huupv@huupv devopsroles]$

The screen output terminal

Conclusion

Thought the article, How to use “Bash script copy rename multiple files” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Linux shell script tips

In this tutorial, How do I use Linux shell script tips? shell script the essential for DevOps Roles.

Linux shell script tips

Load any functions file into the current shell script or a command prompt.

# source command
source ~/.bashrc
# or .
. ~/.bashrc

Do not display output on terminal

[huupv@huupv devopsroles]$ echo devopsroles > /dev/null 2>&1

To display the time in the upper right corner on the terminal

[huupv@huupv devopsroles]$ while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-30));date;tput rc;done &

The screen output terminal as below

Linux date 7 days ago

[huupv@huupv devopsroles]$ date +"%Y-%m-%d" --date "-7 day"

The screen output terminal as below

Waiting for background processes to finish

[huupv@huupv devopsroles]$ sleep 100 & wait $!

Positional parameters in Linux

[huupv@huupv devopsroles]$ foo=(dev ops COM)
[huupv@huupv devopsroles]$ echo ${foo[2]:0}
>COM

Handling arrays in the shell script

[huupv@huupv devopsroles]$ foo=(x y z)
[huupv@huupv devopsroles]$ echo ${foo[2]}
>z
[huupv@huupv devopsroles]$ echo ${#foo}
>1

URL tips

[huupv@huupv devopsroles]$ url=https://www.devopsroles.com/huupv

If you want to retrieve user

$ echo ${url##*/}
> huupv

Retrieve the domain

[huupv@huupv devopsroles]$ echo ${url%/*}
> https://www.devopsroles.com

You want to retrieve the protocol

[huupv@huupv devopsroles]$ echo ${url%%/*}
> https:

The screen output terminal as below

Conclusion

Thought the article, How to use Linux shell script tips as above. I hope will this your helpful.

Bash script opening application

In this tutorial, I have written a small program opening application by the shell script. Linux the essential for DevOps Roles.
I will create the directory and create a file openapp. Let’s begin!

[huupv@huupv devopsroles]$ mkdir myall && cd $_
[huupv@huupv myall]$ pwd
/home/huupv/devopsroles/myall
[huupv@huupv myall]$ touch openapp

Bash script opening application

#!/bin/bash

if [ $1 = "fb" ]; then
  echo Opening facebook
  python -m webbrowser -t "https://www.facebook.com/"
elif [ $1 = "web" ]; then
  echo Opening My Website 
  python -m webbrowser -t "https://www.devopsroles.com/"
  python -m webbrowser -t "https://www.huuphan.com/"
elif [ $1 = "youtube" ]; then
  echo Opening youtube
  python -m webbrowser -t "https://www.youtube.com/user/SystemOperatinglinux"
fi

Add permission to execute.

[huupv@huupv myall]$ chmod +x openapp

Now, I opening Youtube with my shell script.

[huupv@huupv myall]$ ./openapp youtube

The screen output terminal as below

Conclusion

Thought the article, How to use Bash script opening application as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to kill specific processes in Linux

Introduction

This guide will walk you through how to kill specific processes in Linux, from basic commands to advanced techniques, with practical examples. Whether you’re new to Linux or looking to refine your skills, mastering these commands can save you time and enhance system stability.

Linux is a powerful and flexible operating system, used in a variety of environments, from personal desktops to complex server systems. One essential aspect of managing a Linux system effectively is understanding how to handle running processes, especially when they behave unexpectedly or consume too many resources.

Why Kill Processes in Linux?

Processes in Linux are essentially tasks or programs that are currently running on the system. Sometimes, these processes can become unresponsive, hog system resources, or even cause the system to crash. In such cases, killing the process becomes essential to free up resources and maintain the smooth operation of the system. This article provides a comprehensive look at various ways to kill processes based on different criteria, allowing you to manage your Linux system with greater efficiency.

How to View Running Processes

Before killing any process, it’s crucial to know how to view the processes running on your system. You can use several commands to list active processes.

Using ps

The ps command provides a static snapshot of all currently running processes:

ps aux
  • a: Shows processes for all users.
  • u: Displays processes in a user-oriented format.
  • x: Lists processes not connected to a terminal.

Using top and htop

The top and htop commands give a real-time view of running processes.

top

For a more user-friendly interface, install and use htop:

htop

kill specific processes in Linux

For example, kill all PID of the browser Firefox. But not kill line “grep –color=auto firefox” as the picture below

Use ps command with “-ef” option the display PID of browser Firefox.

[huupv@huupv devopsroles]$ ps -ef | grep firefox

The only display PID of Firefox as command below

[huupv@huupv devopsroles]$ ps -ef | grep firefox | grep -v "grep" | awk '{print $2}'

The screen output terminal as below

Using kill command to kill all Processes for Firefox as command line below

[huupv@huupv devopsroles]$ sudo kill -9 $(ps -ef | grep firefox | grep -v "grep" | awk '{print $2}')

Frequently Asked Questions (FAQ)

How do I kill a process without knowing its PID?

You can use pkill or killall to kill a process by name.

What’s the difference between kill and kill -9?

The default kill (SIGTERM) requests a graceful shutdown, while kill -9 (SIGKILL) forcefully stops the process.

Is there any risk in using kill -9?

kill -9 terminates a process immediately without cleanup, so unsaved data may be lost. Use it only when necessary.

How can I kill processes that belong to another user?

To kill processes owned by another user, you need root privileges. Use sudo pkill -u [username].

Why is xkill not working on my Linux distribution?

Some distributions don’t have xkill installed by default. You can install it using your package manager.

External Resources

Conclusion

Managing processes in Linux is a fundamental skill that improves your efficiency and control over the system. This guide has covered essential commands for killing specific processes, from using kill and pkill to more advanced techniques. Practice these commands to confidently handle any unresponsive or resource-consuming processes on your system. Remember to exercise caution, especially with kill -9, and ensure you understand the implications of terminating critical processes. By mastering these techniques, you’ll be better equipped to maintain a smooth-running Linux environment. Thank you for reading the DevopsRoles page!

How to update vagrant box

Introduction

In this tutorial, we will explore the crucial process of update vagrant box, an essential tool for DevOps roles. Keeping your Vagrant box up-to-date ensures you have access to the latest features and improvements.

Locating Vagrant Boxes

Start by browsing the Vagrant Box repository at Vagrant Box Search. Here, you can find a variety of boxes tailored to different development needs.

https://app.vagrantup.com/boxes/search

Automating Guest Addition Installation:

To streamline your workflow, consider using the vagrant-vbguest plugin. Install it effortlessly with the following command:

$ vagrant plugin install vagrant-vbguest

This plugin automatically installs guest additions on the guest side, saving you time and effort.

Update vagrant box

Now, let’s dive into the core of the tutorial—updating your Vagrant box. Utilize the following command structure:

$ vagrant box update --box [box-name]

Note: It’s important to note that when updating the box file, old and new versions may coexist.

Conclusion

Throughout this article, we’ve walked through the steps of using vagrant box update. By following these guidelines, you can ensure your Vagrant box is always equipped with the latest enhancements. I hope this information proves helpful for your DevOps journey. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version