Long questions

1.Write a shell script to print below pattern 

 #!/bin/bash

# Number of rows for the pattern

rows=4

# Loop through each row

for ((i=0; i<rows; i++)); do

    # Print numbers from 0 to i

    for ((j=0; j<=i; j++)); do

        echo -n "$j "

    done

    # Move to the next line after each row

    echo

done

2.Write a shell script to compile all C files and delete those files having errors.  

#!/bin/bash

# Compile each .c file in the current directory

for file in *.c; do

    # Check if there are any .c files

    if [ ! -e "$file" ]; then

        echo "No .c files found."

        exit 1

    fi

 # Try to compile the .c file

    gcc "$file" -o "${file%.c}.out"

 # Check if the compilation was successful

    if [ $? -ne 0 ]; then

        echo "Compilation failed for $file. Deleting the file."

        rm "$file"

    else

        echo "Compiled $file successfully."

    fi

done

3.Write a shell script to print below pattern

1

1 2 1

1 3 3 1

 #!/bin/bash

# Number of rows for the pattern

rows=3

# Function to calculate binomial coefficient

binomial_coefficient() {

    n=$1

    k=$2

    res=1

    for (( i=0; i<k; i++ )); do

        res=$((res * (n - i) / (i + 1)))

    done

    echo $res

}

# Generate Pascal's Triangle

for (( i=0; i<rows; i++ )); do

    for (( j=0; j<=i; j++ )); do

        # Print binomial coefficient

        echo -n "$(binomial_coefficient $i $j) "

    done

    echo "" # Move to the next line

done

3.Write a docker compose file for mysql installation 

4.Write a docker compose file for mysql user creation 

version: "3.7"

services:

  mysql:

    image: mysql:8.0.38

    container_name: mysql-8.0.38

    restart: always                       # always restart

    environment:

      MYSQL_DATABASE: 'MCS_Test'              # name of database

      MYSQL_USER: 'student'                # sample is the name of user

      MYSQL_PASSWORD: 'password'          # password for sample user

      MYSQL_ROOT_PASSWORD: 'password'     # password for root user

    ports:

      - '3306:3306'                       # host port 3306 is mapper to docker port 3306

    expose:

      - '3306'

    volumes:

      - mysql-db:/var/lib/mysql

volumes:

        mysql-db:

Long answer 12,13,14

pipeline{

    agent any

    stages{

        stage("Clone repository")

        {

            steps

            {

                git branch:'main',url:'https://github.com/bushrasayyed/Jenkins.git'

            }

        }

        stage("Install dependencies")

        {

            steps{

                sh 'npm install'

            }

        }

        // stage("Testing")

        // {

        //     steps{

        //         sh 'npm test'

        //     }

        // }

        stage("Start the app")

        {

            input{

                message'Do you want to start?'

                ok "Click on OK"

                submitter 'Bushra'

            }

          steps{

           sh 'npm start'

          }}}}

8.Pull a ubuntu image from docker hub and execute ls commandDocker command 

#installation of docker

0.lsb_release -a , sudo

1.sudo apt update 

2.sudo apt install docker.io

3.sudo systemctl enable docker --now

4.docker --version

#add user to docker

5.who

6.sudo usermod -aG $admin1

7.sudo usermod -aG $USER

8.getent group docker 

9.newgrp docker

10.sudo service docker restart 

11.docker ps

Go to browser - search "docker pull Ubuntu image"

12.docker pull Ubuntu 

13.docker ps

14.docker images

Copy image ID

15.docker run -i -t (image_name /id) /bin/bash

16.ls 

17.cd/etc

18.cd ..

19.docker ps-a

7.Execute below docker commands:#first delete the container and the delete the image docker exec,docker rm,docker rmi

1.docker ps 

# it show all containers active and inactive 

2.docker ps -a

# it show active container 

#copy container id

#delete the container first

3.docker rm (container_Id)

#brakets mat dallo

#delete image 

4.docker rmi (image_id)

#port mapping

5. Docker images

6. Docker run -d --restart = always -p 80:80 ( image_id)

7. Docker ps-a

8. Docker exec -it (container_id ) /bin/bash




Comments

Popular posts from this blog

Shorts question