Skip to content

Homework assignment 2 solution for Cloud Computing course.

Notifications You must be signed in to change notification settings

AmeerQatmosh/Bash-Script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Bash-Script - Cloud Computing

Bash script is a type of script that is written in the Bash programming language, which is a Unix shell and command language,It is commonly used in Linux and Unix-based operating systems as a means of automating repetitive tasks and simplifying complex operations.

First Script - LinuxStatus:

To create a bash script in Linux:

Step 1: Open Terminal and run this command: touch LinuxStatus.

Step 2: Open and edit the Script file by run this command: sudo nano LinuxStatus.

Step 3: Write the Script as in this file: LinuxStatus.sh

Step 4: to test the script run this command: LinuxStatus.

image

To add the script to your Linux PATH, follow these steps:

  1. Use the ls command to verify that the script is in the directory.
  2. Use the echo $PATH to see the directories that are in the PATH.
  3. Copy script to one of the directories in the PATH. For example, using this command sudo cp LinuxStatus.sh /usr/local/bin to copy the script to the /usr/local/bin directory.
  4. Run this command: sudo mv LinuxStatus /usr/local/bin
  5. Make sure that the script executable by running the command sudo chmod +x /usr/local/bin/LinuxStatus or sudo chmod 700 /usr/local/bin/LinuxStatus This will allow to run the script from anywhere on your system.
  6. Verify that the script is now in the PATH by running the command which LinuxStatus This should output the full path of the script.

image

  1. After this you can run the script in anywhare in terminal, and with an any options, For Example: run these commands:

LinuxStatus p for option 1.

LinuxStatus r for option 2.

LinuxStatus h for option 3.

LinuxStatus a for option 4.

Mix options for example LinuxStatus p r c for option 1,2,4.

This following Demo shows how the script implemented:

LinuxStatus.Script.Demo.webm

After completing these steps, you should be able to run the LinuxStatus command from anywhere in your Linux terminal.

Second Script - cronJob:

To create a bash script in Linux:

Step 1: Open Terminal and run this command: touch cronJob.sh.

Step 2: Open and edit the Script file by run this command: sudo nano cronJob.sh.

Step 3: Write the Script as in this file: cronJob.sh

Step 4: to test the script run this command: bash cronJob.sh.

image

Run this command to make sure that the installition is successed, curl -I http://localhost

image

To run this script as a cronjob daily at midnight, do the following Steps:

  1. Make sure that curl packege is installed, if it's not, install it be running this command: sudo apt-get install curl, but it recommended first to run this command sudo apt-get update.

  2. Run this command: sudo crontab -e

image

  1. Add this line to the end of the file: 0 0 * * * /bin/bash /path/to/cronjob.sh and make sure to give the right path for cronJob.sh file, In other words Make sure to replace /path/to/cronjob.sh with the actual path to your bash script:

image

About

Homework assignment 2 solution for Cloud Computing course.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages