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.
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
.
- Use the
ls
command to verify that the script is in the directory. - Use the
echo $PATH
to see the directories that are in the PATH. - 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. - Run this command:
sudo mv LinuxStatus /usr/local/bin
- Make sure that the script executable by running the command
sudo chmod +x /usr/local/bin/LinuxStatus
orsudo chmod 700 /usr/local/bin/LinuxStatus
This will allow to run the script from anywhere on your system. - Verify that the script is now in the PATH by running the command
which LinuxStatus
This should output the full path of the script.
- 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.
LinuxStatus.Script.Demo.webm
After completing these steps, you should be able to run the LinuxStatus command from anywhere in your Linux terminal.
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
.
Run this command to make sure that the installition is successed, curl -I http://localhost
-
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 commandsudo apt-get update
. -
Run this command:
sudo crontab -e
- 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: