Advertisement
tampurus

Project all 10 case studies GS GOURAV_UPADHYAY

Apr 17th, 2024
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.64 KB | None | 0 0
  1. 1 digital clock
  2. echo "Digital Clock for Linux"
  3. echo "To exit please press ctrl + c "
  4.  
  5. while :
  6. do
  7.     clear
  8.     tput setaf 1             # Set text color to green
  9.     tput cup 10 69           # Adjusted position for a larger display
  10.     date +"%r"
  11.     #tput sgr0                # Reset text attributes
  12.     sleep 1
  13. done
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. 2
  24.  
  25. #!/bin/bash
  26. # Function to display the sign-up form
  27. display_form() {
  28.     echo "Welcome to the Sign-Up Form"
  29.     echo "---------------------------"
  30.     read -p "Enter your username: " username
  31.     read -sp "Enter your password (at least 8 characters): " password
  32.     echo
  33.     while [ ${#password} -lt 8 ]; do
  34.         echo "Password must have at least 8 characters."
  35.         read -sp "Enter your password (at least 8 characters): " password
  36.         echo
  37.     done
  38.     read -p "Enter your email address: " email
  39.     echo
  40.     echo "Thank you for signing up, $username!"
  41.     echo "Your email address is: $email"
  42. }
  43.  
  44.  
  45. # Main function
  46. main() {
  47.     display_form
  48. }
  49. # Calling the main function
  50. Main
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. 3
  63. #!/bin/bash
  64.  
  65. # Initialize variables to store inventory and prices
  66. declare -A inventory
  67. declare -A prices
  68.  
  69.  
  70. # Function to add items to inventory
  71. add_item() {
  72.     item_name=$1
  73.     item_quantity=$2
  74.     item_price=$3
  75.  
  76.  
  77.     inventory["$item_name"]=$item_quantity
  78.     prices["$item_name"]=$item_price
  79. }
  80.  
  81.  
  82. # Function to display available items and prices
  83. display_inventory() {
  84.     echo "Available Items in the Medical Store:"
  85.     echo "-----------------------------------"
  86.     for item in "${!inventory[@]}"; do
  87.         echo "Item: $item - Quantity: ${inventory[$item]} - Price: ${prices[$item]}"
  88.     done
  89. }
  90.  
  91.  
  92. # Function to sell items
  93. sell_item() {
  94.     item_name=$1
  95.     item_quantity=$2
  96.  
  97.  
  98.     current_quantity=${inventory["$item_name"]}
  99.     if [ "$current_quantity" -lt "$item_quantity" ]; then
  100.         echo "Sorry, only $current_quantity $item_name(s) available."
  101.     else
  102.         echo "Sold $item_quantity $item_name(s) for $((item_quantity * prices["$item_name"]))"
  103.         inventory["$item_name"]=$((current_quantity - item_quantity))
  104.     fi
  105. }
  106.  
  107.  
  108. # Main function
  109. main() {
  110.     add_item "Paracetamol" 50 5
  111.     add_item "Bandages" 100 3
  112.     add_item "Antiseptic" 30 7
  113.  
  114.  
  115.     display_inventory
  116.  
  117.  
  118.     echo "Welcome to the Mini Medical Store"
  119.     echo "--------------------------------"
  120.     read -p "Enter the item you want to purchase: " item_name
  121.     read -p "Enter the quantity: " quantity
  122.  
  123.  
  124.     sell_item "$item_name" "$quantity"
  125.  
  126.  
  127.     display_inventory
  128. }
  129.  
  130.  
  131. # Calling the main function
  132. main
  133.  
  134.  
  135.  
  136.  
  137.  
  138. 4
  139.  
  140. #!/bin/bash
  141.  
  142.  
  143. # Initialize associative arrays to store books and their availability
  144. declare -A books
  145. declare -A availability
  146.  
  147.  
  148. # Function to add books to the library
  149. add_book() {
  150.     title=$1
  151.     author=$2
  152.     availability["$title"]="available"
  153.     books["$title"]=$author
  154. }
  155.  
  156.  
  157. # Function to display available books
  158. display_books() {
  159.     echo "Available Books in the Library:"
  160.     echo "--------------------------------"
  161.     for title in "${!books[@]}"; do
  162.         echo "Title: $title - Author: ${books[$title]} - Availability: ${availability[$title]}"
  163.     done
  164. }
  165.  
  166.  
  167. # Function to borrow a book
  168. borrow_book() {
  169.     title=$1
  170.  
  171.  
  172.     if [ "${availability[$title]}" = "available" ]; then
  173.         availability["$title"]="borrowed"
  174.         echo "You have borrowed the book: $title"
  175.     else
  176.         echo "Sorry, the book $title is currently not available."
  177.     fi
  178. }
  179.  
  180.  
  181. # Function to return a book
  182. return_book() {
  183.     title=$1
  184.  
  185.  
  186.     if [ "${availability[$title]}" = "borrowed" ]; then
  187.         availability["$title"]="available"
  188.         echo "You have returned the book: $title"
  189.     else
  190.         echo "This book is not borrowed or doesn't exist in the library."
  191.     fi
  192. }
  193.  
  194.  
  195. # Main function
  196. main() {
  197.     add_book "1984" "George Orwell"
  198.     add_book "To Kill a Mockingbird" "Harper Lee"
  199.     add_book "The Great Gatsby" "F. Scott Fitzgerald"
  200.  
  201.  
  202.     display_books
  203.  
  204.  
  205.     echo "Welcome to the Mini Library Management System"
  206.     echo "---------------------------------------------"
  207.     echo "1. Borrow a Book"
  208.     echo "2. Return a Book"
  209.     echo "3. Exit"
  210.  
  211.  
  212.     read -p "Enter your choice: " choice
  213.  
  214.  
  215.     case $choice in
  216.         1)
  217.             read -p "Enter the title of the book you want to borrow: " title
  218.             borrow_book "$title"
  219.             ;;
  220.         2)
  221.             read -p "Enter the title of the book you want to return: " title
  222.             return_book "$title"
  223.             ;;
  224.         3)
  225.             echo "Exiting..."
  226.             ;;
  227.         *)
  228.             echo "Invalid choice. Please enter a valid option."
  229.             ;;
  230.     esac
  231.  
  232.  
  233.     display_books
  234. }
  235.  
  236.  
  237. # Calling the main function
  238. main
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255. 5
  256.  
  257. #!/bin/bash
  258.  
  259.  
  260. # Initialize associative arrays to store menu items and their prices
  261. declare -A menu
  262. declare -A order
  263.  
  264.  
  265. # Function to add menu items
  266. add_item() {
  267.     item_name=$1
  268.     item_price=$2
  269.  
  270.  
  271.     menu["$item_name"]=$item_price
  272. }
  273.  
  274.  
  275. # Function to display the menu
  276. display_menu() {
  277.     echo "Menu:"
  278.     echo "-----"
  279.     for item in "${!menu[@]}"; do
  280.         echo "$item - ₹${menu[$item]}"
  281.     done
  282. }
  283.  
  284.  
  285. # Function to take customer orders
  286. take_order() {
  287.     while true; do
  288.         read -p "Enter the item you want to order (or type 'done' to finish): " item
  289.         if [ "$item" == "done" ]; then
  290.             break
  291.         elif [ -z "${menu[$item]}" ]; then
  292.             echo "Sorry, $item is not on the menu."
  293.         else
  294.             read -p "Enter the quantity: " quantity
  295.             order["$item"]=$((order["$item"] + quantity))
  296.         fi
  297.     done
  298. }
  299.  
  300.  
  301. # Function to calculate and display the total bill
  302. calculate_bill() {
  303.     total=0
  304.     echo "Order Summary:"
  305.     echo "--------------"
  306.     for item in "${!order[@]}"; do
  307.         price=$((${menu[$item]} * ${order[$item]}))
  308.         echo "$item x ${order[$item]} - ₹$price"
  309.         total=$((total + price))
  310.     done
  311.     echo "Total: ₹$total"
  312. }
  313.  
  314.  
  315. # Main function
  316. main() {
  317.     add_item "Burger" 100
  318.     add_item "Pizza" 150
  319.     add_item "Salad" 80
  320.  
  321.  
  322.     display_menu
  323.  
  324.  
  325.     echo "Welcome to the Mini Restaurant Management System"
  326.     echo "-----------------------------------------------"
  327.     take_order
  328.  
  329.  
  330.     calculate_bill
  331. }
  332.  
  333.  
  334. # Calling the main function
  335. Main
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350. 6
  351.  
  352.  
  353. #!/bin/bash
  354.  
  355. # Function to perform addition
  356. add() {
  357.     echo "$1 + $2" | bc
  358. }
  359.  
  360.  
  361. # Function to perform subtraction
  362. subtract() {
  363.     echo "$1 - $2" | bc
  364. }
  365.  
  366.  
  367. # Function to perform multiplication
  368. multiply() {
  369.     echo "$1 * $2" | bc
  370. }
  371.  
  372.  
  373. # Function to perform division
  374. divide() {
  375.     echo "scale=2; $1 / $2" | bc
  376. }
  377.  
  378.  
  379. # Main function
  380. main() {
  381.     echo "Simple Calculator"
  382.     echo "-----------------"
  383.     echo "1. Addition"
  384.     echo "2. Subtraction"
  385.     echo "3. Multiplication"
  386.     echo "4. Division"
  387.     read -p "Enter your choice: " choice
  388.  
  389.  
  390.     case $choice in
  391.         1)
  392.             read -p "Enter first number: " num1
  393.             read -p "Enter second number: " num2
  394.             echo "Result: $(add $num1 $num2)"
  395.             ;;
  396.         2)
  397.             read -p "Enter first number: " num1
  398.             read -p "Enter second number: " num2
  399.             echo "Result: $(subtract $num1 $num2)"
  400.             ;;
  401.         3)
  402.             read -p "Enter first number: " num1
  403.             read -p "Enter second number: " num2
  404.             echo "Result: $(multiply $num1 $num2)"
  405.             ;;
  406.         4)
  407.             read -p "Enter first number: " num1
  408.             read -p "Enter second number: " num2
  409.             if [ "$num2" -eq 0 ]; then
  410.                 echo "Error: Division by zero"
  411.             else
  412.                 echo "Result: $(divide $num1 $num2)"
  413.             fi
  414.             ;;
  415.         *)
  416.             echo "Invalid choice"
  417.             ;;
  418.     esac
  419. }
  420.  
  421.  
  422. # Calling the main function
  423. main
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433. 7
  434.  
  435. #!/bin/bash
  436. # Function to generate a random password
  437. generate_password() {
  438.     local length=$1
  439.     tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$length" | head -n 1
  440. }
  441.  
  442.  
  443. # Main function
  444. main() {
  445.     echo "Password Generator"
  446.     echo "------------------"
  447.     read -p "Enter the length of the password: " password_length
  448.     generated_password=$(generate_password "$password_length")
  449.     echo "Generated Password: $generated_password"
  450. }
  451.  
  452.  
  453. # Calling the main function
  454. main
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464. 8
  465.  
  466. #!/bin/bash
  467.  
  468. # Define the filename for the database
  469. DB_FILE="student_database.txt"
  470.  
  471.  
  472. # Function to create a new database file
  473. create_database() {
  474.     touch "$DB_FILE"
  475.     echo "Database created successfully."
  476. }
  477.  
  478.  
  479. # Function to view the contents of the database
  480. view_database() {
  481.     echo "Student Database:"
  482.     echo "-----------------"
  483.     cat "$DB_FILE"
  484. }
  485.  
  486.  
  487. # Function to insert a new student record
  488. insert_record() {
  489.     read -p "Enter student ID: " id
  490.     read -p "Enter student name: " name
  491.     read -p "Enter student age: " age
  492.     echo "$id | $name | $age" >> "$DB_FILE"
  493.     echo "Record inserted successfully."
  494. }
  495.  
  496.  
  497. # Function to update a student record
  498. update_record() {
  499.     read -p "Enter student ID to update: " id
  500.     read -p "Enter new name: " new_name
  501.     read -p "Enter new age: " new_age
  502.     sed -i "s/^$id .*/$id | $new_name | $new_age/" "$DB_FILE"
  503.     echo "Record updated successfully."
  504. }
  505.  
  506.  
  507. # Function to delete a student record
  508. delete_record() {
  509.     read -p "Enter student ID to delete: " id
  510.     sed -i "/^$id/d" "$DB_FILE"
  511.     echo "Record deleted successfully."
  512. }
  513.  
  514.  
  515. # Function to show a particular student record
  516. show_record() {
  517.     read -p "Enter student ID to view: " id
  518.     grep "^$id" "$DB_FILE"
  519. }
  520.  
  521.  
  522. # Main function
  523. main() {
  524.     while true; do
  525.         echo "Student Database Operations:"
  526.         echo "1. Create Database"
  527.         echo "2. View Database"
  528.         echo "3. Insert Record"
  529.         echo "4. Update Record"
  530.         echo "5. Delete Record"
  531.         echo "6. Show Record for Particular Student"
  532.         echo "7. Exit"
  533.         read -p "Enter your choice: " choice
  534.  
  535.  
  536.         case $choice in
  537.             1) create_database ;;
  538.             2) view_database ;;
  539.             3) insert_record ;;
  540.             4) update_record ;;
  541.             5) delete_record ;;
  542.             6) show_record ;;
  543.             7) echo "Exiting..." && exit ;;
  544.             *) echo "Invalid choice. Please enter a valid option." ;;
  545.         esac
  546.     done
  547. }
  548.  
  549.  
  550. # Calling the main function
  551. main
  552.  
  553.  
  554.  
  555.  
  556. 9
  557.  
  558. #!/bin/bash
  559.  
  560.  
  561. # Define the directory where the files are located
  562. DIRECTORY="/home/me/gourav_upadhyay/shell"
  563.  
  564.  
  565. # Function to remove files older than 4 days based on their filenames
  566. remove_old_files() {
  567.     find "$DIRECTORY" -type f -name "*.*" -mtime +4 -exec rm {} \;
  568.     echo "Old files older than 4 days have been removed from $DIRECTORY"
  569. }
  570.  
  571.  
  572. # Main function
  573. main() {
  574.     echo "Removing files older than 4 days in $DIRECTORY"
  575.     remove_old_files
  576. }
  577.  
  578.  
  579. # Calling the main function
  580. main
  581.  
  582.  
  583.  
  584.  
  585. 10
  586.  
  587. #!/bin/bash
  588.  
  589.  
  590. # Function to count words, lines, and characters in a text file
  591. count_stats() {
  592.     file="$1"
  593.     words=$(wc -w < "$file")
  594.     lines=$(wc -l < "$file")
  595.     characters=$(wc -m < "$file")
  596.     echo "File: $file"
  597.     echo "Words: $words"
  598.     echo "Lines: $lines"
  599.     echo "Characters: $characters"
  600.     echo "---------------------"
  601. }
  602.  
  603.  
  604. # Main function
  605. main() {
  606.     echo "Counting statistics for the provided text files"
  607.     echo "----------------------------------------------"
  608.     file1="/home/me/gourav_upadhyay/shell/file1.sh"
  609.     file2="/home/me/gourav_upadhyay/shell/file2.sh"
  610.     count_stats "$file1"
  611.     count_stats "$file2"
  612. }
  613.  
  614.  
  615. # Calling the main function
  616. main
  617.  
  618.  
  619.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement