Thursday 10 October 2019

how many ways to create file using perl?

Method 1:

open(FHE,">file1.txt");


Method 2:

readpipe( "touch kkm.txt" );


Method 3:

system("touch kkm.txt");


Method 4:

open(my $file, '|-', "touch kkm.txt");


Method 5:

 `touch kkp.txt`;


Method 6:

qx/touch kkm.txt/;


Method 7:[always execute exec at eof]

exec("touch kkm.txt");


Method 8:

readpipe( "echo  > file1.txt" );


Method 9:

system("echo  > file2.txt");


Method 10:

`echo  > file3.txt`;


Method 11:

qx/echo  > file4.txt/;


Method 12:

open(my $file, '|-', "echo  > file5.txt");


Method 13:[always execute exec at eof]

exec("echo  > file6.txt");


Method 14:

readpipe( "cat '' > cat1111.txt" );


Method 15:

system("cat '' > cat1112.txt");


Method 16:

`cat '' > cat1113.txt`;


Method 17:

qx/cat '' > cat1114.txt/;


Method 18:

open(my $file, '|-', "cat '' > cat1115.txt");


Method 19:[always execute exec at eof]

exec("cat '' > cat1116.txt");


Method 20:

readpipe( "print  > cat1111.txt" );


Method 21:

system("print  > cat1112.txt");


Method 22:

`print  > cat1113.txt`;


Method 23:

qx/print > cat1114.txt/;


Method 24:

open(my $file, '|-', "print  > cat1115.txt");


Method 25:[always execute exec at eof]

exec("print  > cat1116.txt");


Method 26:[always execute exec at eof]

exec "vim   >  file.txt";

Kill process by using any one kill command

pkill vim;


Method 27:[always execute exec at eof]

exec "vi  >  file.txt";

Kill process by using any one kill command

pkill vi;


Method 28:[always execute exec at eof]

exec "nano  >  file.txt";

Kill process by using any one kill command

pkill nano;


Thursday 21 March 2024

Troubleshoot Application Failures with Kubernetes!


 In the dynamic world of containerized applications, where Kubernetes reigns as the orchestrator of choice, encountering issues is not uncommon. Whether it’s a pod failing to start, a service unreachable, or unexpected behavior within your cluster, efficient troubleshooting is crucial to maintain the reliability and performance of your applications. In this guide, we’ll explore some essential techniques and tools to diagnose and resolve common problems in Kubernetes.

Read more »

Labels:

Monday 18 March 2024

Essential Kubectl Commands for Every DevOps Engineer


 As the complexity of software development grows, so does the need for efficient and reliable deployment solutions. Kubernetes, an open-source platform designed to automate deploying, scaling, and operating application containers, has become the go-to solution for managing containerized applications. However, navigating through Kubernetes’ vast functionalities can be daunting for many, especially for DevOps engineers tasked with maintaining the health and performance of applications. This is where kubectl, Kubernetes’ command-line tool, becomes invaluable.

Read more »

Labels:

Tuesday 15 October 2019

How to run Linux Command Using Perl?

Method 1:

@a=print readpipe( "ls -l *" );

print @a;


Method 2:

@a=print system( "ls -l *" ); print @a;


Read more »

Labels:

Tuesday 12 March 2024

Docker Container Commands for a DevOps Engineer


Read more »

Labels:

Sunday 9 October 2022

Building and Deploying a Containerized Application with Amazon Elastic Kubernetes Service - Lab

 SPL-BE-200-COCEKS-1 - Version 1.0.8

© 2023 Amazon Web Services, Inc. or its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in part, without prior written permission from Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited. All trademarks are the property of their owners.

Note: Do not include any personal, identifying, or confidential information into the lab environment. Information entered may be visible to others.

Corrections, feedback, or other questions? Contact us at AWS Training and Certification.

Read more »

Labels: ,

Friday 25 February 2022

Connecting from Inside a Docker Container to the Localhost of the Host Machine

Docker has revolutionized the way we build, ship, and run applications. It allows us to encapsulate our applications and their dependencies in containers, providing a consistent and isolated environment for running them. However, working with Docker containers sometimes raises challenges, especially when trying to access services running on the host machine, such as databases or APIs exposed on localhost.

In this blog post, we will explore the steps to connect from inside a Docker container to the localhost of the host machine. We will cover various scenarios, including connecting to services running on different ports and accessing services on both Linux and Windows host machines. We will also provide code examples and explanations for each step.

Step 1: Understand Docker Networking Basics

Docker containers have their own networking stack, which means that by default, they are isolated from the host machine's network. This isolation is done for security and stability reasons. However, it also means that if you try to access the host machine's localhost from inside a Docker container, you will encounter a connection error.

Step 2: Use Host Networking Mode

One way to allow a Docker container to access the host machine's localhost is by using the host networking mode. In this mode, the container shares the host machine's network namespace, allowing it to directly access the host's network interfaces. However, this mode has some security implications, as it exposes all host ports to the container.

docker run --network host <your_image>

Step 3: Use Docker Host IP Address

Another approach is to use the host machine's IP address instead of localhost. Docker provides a special DNS name "host.docker.internal" that resolves to the IP address of the host machine. This can be used as a replacement for localhost when connecting from inside the container.

Example (Python):

import requests

response = requests.get('http://host.docker.internal:8000/api')
print(response.text)


Step 4: Use Custom Docker Bridge Network

If you want more control over the networking and avoid using the host network mode, you can create a custom Docker bridge network and attach the container to it. This allows you to access services running on the host machine by using the host's IP address and the exposed port.

Example:

# Create a custom bridge network
docker network create my_bridge_network

# Run the container attached to the custom network
docker run --network my_bridge_network <your_image>


Step 5: Port Forwarding

In some cases, you may want to access a service running on a specific port on the host machine from inside the Docker container. In such scenarios, you can use port forwarding to map a port on the host to a port on the container.

Example:

# Forward port 8000 on the host to port 80 on the container
docker run -p 8000:80 <your_image>


Step 6: Consider Firewall and Security Settings

When connecting from inside a Docker container to the host machine's localhost or IP address, ensure that any firewalls or security settings on the host machine do not block the connection. In some cases, you may need to adjust firewall rules to allow incoming connections from Docker containers.


Let's walk through an example to demonstrate how to connect from inside a Docker container to the localhost of the host machine using the "host.docker.internal" DNS name.


Step 1: Create a Simple Flask API on the Host Machine

First, let's create a simple Flask API running on the host machine. This API will listen on port 8000 and respond with a "Hello, Docker!" message.

Create a file named app.py with the following content:


from flask import Flask

app = Flask(__name__)

@app.route('/api')
def hello():
    return 'Hello, Docker!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)


Step 2: Run the Flask API on the Host Machine

Open a terminal or command prompt and navigate to the directory where app.py is located. Then, run the Flask API using the following command:

python app.py


The Flask API should now be running on http://localhost:8000/api.

Step 3: Create a Docker Container to Access the API

Now, let's create a Docker container that will access the Flask API running on the host machine. We will use the python:3.9 base image and install the requests library to make HTTP requests to the API.

Create a file named `Dockerfile` with the following content:


# Use the Python 3.9 base image
FROM python:3.9

# Install the requests library
RUN pip install requests

# Set the working directory inside the container
WORKDIR /app

# Copy the Python script into the container
COPY app.py /app/app.py

# Run the Python script when the container starts
CMD ["python", "app.py"]


Step 4: Build and Run the Docker Container

Open a terminal or command prompt in the same directory where the Dockerfile and app.py files are located. Build the Docker image using the following command:

docker build -t my_flask_app .

Next, run the Docker container using the following command:

docker run -p 8000:8000 my_flask_app


Step 5: Access the Flask API from Inside the Docker Container

The Docker container is now running and should be able to access the Flask API on the host machine. Inside the container, we can use the requests library to make an HTTP request to the API.

Create a new terminal or command prompt window, and run the following command to access the Docker container:

docker exec -it <container_id> /bin/bash


Replace <container_id> with the ID of the running container. Once inside the container, run the following Python script:

import requests

response = requests.get('http://host.docker.internal:8000/api')
print(response.text)


This script will make an HTTP GET request to the Flask API running on the host machine using the "host.docker.internal" DNS name. It should print the "Hello, Docker!" message returned by the API.


In this example, we have seen, how to connect from inside a Docker container to the localhost of the host machine using the "host.docker.internal" DNS name. By leveraging this DNS name, we can access services running on the host machine from within the Docker container, making it easier to interact with services and applications during development and testing.

Labels: , ,

Wednesday 17 March 2021

A beginner's guide to building desktop applications with Python and PyQt

Python is a powerful programming language that is widely used for developing various types of applications, including desktop applications. One of the popular frameworks for building desktop applications with Python is PyQt. PyQt is a set of Python bindings for the Qt application framework and is used for creating graphical user interfaces (GUIs) for desktop applications. In this beginner's guide, we will explore how to build desktop applications with Python and PyQt.

Installing PyQt

Before we start building our desktop application, we need to install PyQt. PyQt can be installed using pip, the Python package manager. 

Open your terminal or command prompt and enter the following command:

pip install pyqt5


Once PyQt is installed, we are ready to build our first desktop application.

Read more »

Labels: , ,