Git Product home page Git Product logo

bash-script's Introduction

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

bash-script's People

Contributors

ameerqatmosh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.