Introduction to Bash Scripting
Bash scripting allows you to automate tasks on your Linux server by creating a file with a series of commands.
Creating a Simple Script
- Create a new file: `nano myscript.sh`
- Add the "shebang" at the top to tell the system this is a bash script: `#!/bin/bash`
- Add some commands, for example:
#!/bin/bash
# A simple script to update the server and report disk space.
echo "--- Starting Server Update ---"
apt update && apt upgrade -y
echo ""
echo "--- Current Disk Space ---"
df -h
echo ""
echo "--- Script Finished ---"
CopyMaking the Script Executable
Before you can run it, you must make the script executable:
chmod +x myscript.sh
CopyRunning the Script
./myscript.sh
Copy