Linux shell scripts Notes ✔️
Linux shell scripts Notes ✔️
Shell Scripts
👉Mahesh Sarjerao Girhe [ MSG] ✅
Linkedln:-
https://www.linkedin.com/in/
maheshgirhe7875
1. File Backup Script:
#!/bin/bash
backup_dir="/path/to/backup"
source_dir="/path/to/source"
#!/bin/bash threshold=90
#!/bin/bash username="newuser"
#!/bin/bash
logfile="/path/to/logfile.log"
#!/bin/bash length=12
#!/bin/bash file="/path/to/file.txt"
install "$package" -y
done echo "Packages installed
successfully."
#!/bin/bash host="example.com"
#!/bin/bash
website="https://example.com"
directory="/path/to/cleanup"
#
#!/bin/bash
output_file="cpu_usage_log.txt"
# Log current CPU usage to a file with timestamp echo "$(date) $(top
-bn1 | grep 'Cpu(s)' | awk '{print $2}' | cut -d.
-f1)%" >> "$output_file"
echo "CPU usage logged."
#!/bin/bash
output_file="system_info.txt"
scheduled_task="/path/to/your_script.sh"
schedule_time="0 2 * * *"
Schedule a task using cron echo "$schedule_time
$scheduled_task" | crontab echo "Task scheduled
successfully."
#!/bin/bash threshold=90
source_dir="/path/to/source"
remote_server="user@remoteserver:/path/to/backup"
#!/bin/bash
file_to_compress="/path/to/file.txt"
database_name="your_database"
output_file="database_backup_$(date +%Y%m%d).sql"
#!/bin/bash
git_repo="/path/to/your/repo"
source_dir="/path/to/source"
destination_dir="/path/to/destination"
# Synchronize directories using rsync rsync -
avz "$source_dir" "$destination_dir" echo
"Directories synchronized successfully."
#!/bin/bash
log_file="/var/log/apache2/access.log"
#!/bin/bash
output_file="system_health_check.txt"
database_name="your_database"
days_to_keep=7
#!/bin/bash
service_name="your_service"
#!/bin/bash
folder_path="/path/to/folder"
#!/bin/bash
backup_dir="/path/to/backups"
max_backups=5
remote_server="user@remote-server"
remote_script="/path/to/remote/script.sh"
#!/bin/bash network_interface="eth0"