0% found this document useful (0 votes)
32 views

April 16th: - : "Enter The Value of A:" "Enter The Value of B:"

The document contains code snippets in bash scripting for various tasks like user input validation, user creation, functions, and parameter validation in PowerShell. It includes code to take input from the user, check if it is valid, create users and passwords if valid, define functions to calculate salary details, and PowerShell code to validate parameter types and compare integer values.

Uploaded by

chandu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

April 16th: - : "Enter The Value of A:" "Enter The Value of B:"

The document contains code snippets in bash scripting for various tasks like user input validation, user creation, functions, and parameter validation in PowerShell. It includes code to take input from the user, check if it is valid, create users and passwords if valid, define functions to calculate salary details, and PowerShell code to validate parameter types and compare integer values.

Uploaded by

chandu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

April 16th:

------------
#!/bin/bash
while true; do
read -p "Enter The Value Of A:" A
read -p "Enter The Value Of B:" B
if [ $A -lt $B ]; then
echo "$A less than $B"
elif [ $A -eq $B ]; then
echo "Both Are Equal"
else
echo "$A greater than $B"
fi
done

I=0
while [ $I -lt 11 ]; do
echo "Welcome To DevOp Training Class $I"
I=$(($I + 1))
done

for region in $(cat regions); do


aws s3api create-bucket --bucket devopsb12class3-${region} --region $region
sleep 3
done

for region in $(cat regions); do


aws s3 rb s3://devopsb12class3-${region} --force
sleep 3
done

DEBUGGING:
#!/bin/bash
set -x
read -p "Enter the command:" COMM
$COMM
if [ $? -eq 0 ]; then
echo "You have entered a right command."
else
echo "Comand Not Found"
fi

for I in {2..100}; do
if [ $(expr $I % 2) -eq 0 ]; then
echo "$I is an ODD Number."
fi
done

April 17th:
root@ip-10-1-1-11:~# cat user.sh
#!/bin/bash
while true
do
read -p "Please Enter The User Name:" USERNAME
if [ -n "$USERNAME" ]; then
echo "$USERNAME is valid."
EXUSER=$(cat /etc/passwd | grep -i $USERNAME | cut -d ":" -f 1)
if [ "$EXUSER" == "$USERNAME" ]; then
echo "User $USERNAME Already Exists, Please Select a Diffrent Username"
else
#read -s -p "Please Enter The Password:" PASSWORD
SPECIAL='!@#$%^&*()_+'
SPECCHAR=$(echo $SPECIAL | fold -w 1 | shuf | head -1)
PASSWORD="India${SPECCHAR}${RANDOM}"
useradd -m $USERNAME
echo "$USERNAME:$PASSWORD" | sudo chpasswd
passwd -e $USERNAME
echo "$USERNAME sucessfully created & temp password is $PASSWORD"
fi
else
echo "Invalid Username"
fi
done

----------
#!/bin/bash
if [ $# -eq 0 ]
then
echo "You have entered $# usernames. Please provide a username."
else
for USERNAME in $@
do
#if [ -n "$USERNAME" ]; then
if [[ -n $USERNAME ]] && [[ $USERNAME -eq $USERNAME ]]; then
echo "$USERNAME is valid."
EXUSER=$(cat /etc/passwd | grep -w $USERNAME | cut -d ":" -f 1)
if [ "$EXUSER" == "$USERNAME" ]; then
echo "But User $USERNAME Already Exists, Please Select a Diffrent Username"
else
#read -s -p "Please Enter The Password:" PASSWORD
SPECIAL='!@#$%^&*()_+'
SPECCHAR=$(echo $SPECIAL | fold -w 1 | shuf | head -1)
PASSWORD="India${SPECCHAR}${RANDOM}"
useradd -m $USERNAME
echo "$USERNAME:$PASSWORD" | sudo chpasswd
passwd -e $USERNAME
echo "$USERNAME sucessfully created & temp password is $PASSWORD"
sleep 5
fi
else
echo "Invalid Username"
fi
done
fi

----------------------------
#!/bin/bash

read -p "Enter Username:" USERNAME

if [[ -n $USERNAME ]] && [ $USERNAME -eq $USERNAME 2>/dev/null ]

#if [[ $USERNAME ]] && [ $USERNAME -eq $USERNAME ]

then

echo "input is an integer"

else

read -s -p "please enter the password for $USERNAME :" PASSWORD

echo "$USERNAME successfully created..."


echo "PASSWORD: $PASSWORD"

Fi

FUNCTIONS:

#!/bin/bash

set +x

function gross {

NAME=$1

SALARY=$2

HRA=$(echo $SALARY \* .40 |bc)

echo "HRA for $NAME is $HRA"

GROSSSAL=$(echo $SALARY + $HRA | bc)

echo "Your name is ${NAME} and Total Gross Salary is ${GROSSSAL}"

net

net (){

TAXPER=10

TOTALTAX=$(echo $GROSSSAL / $TAXPER | bc)

NETSAL=$(echo $GROSSSAL - $TOTALTAX | bc)

echo "Your name is ${NAME} and Net Salary is ${NETSAL}"

gross $@

=======================

April 23:
param(

[Parameter(Mandatory)]

[int] $a = $(Read-Host "Please Enter The Value of A"),

[Parameter(Mandatory)]

[int] $b = $(Read-Host "Please Enter The Value of B")

$a.GetType()

$b.GetType()

Write-Output $aerror

if ($a -is [int] -and $b -is [int]) {

if ( $a -gt $b) {

Write-Output "A value is $a is greater than B value of $b"

else {

Write-Output "B value is $b is greater than A value of $a"

else

Write-Output "Enter Only Integers for A and B."


}

You might also like