coba bikin script linux
- User
coba bikin script linux
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
coba bikin script linux
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Berikut adalah beberapa contoh script Linux dalam Bash shell:
#!/bin/bash
# Script backup direktori
BACKUP_DIR="/path/to/backup"
SOURCE_DIR="/path/to/source"
DATE=$(date +"%Y%m%d")
mkdir -p $BACKUP_DIR
tar -czvf $BACKUP_DIR/backup_$DATE.tar.gz $SOURCE_DIR
#!/bin/bash
# Script monitoring sistem
echo "--- Informasi Sistem ---"
echo "Hostname: $(hostname)"
echo "Tanggal: $(date)"
echo "Penggunaan CPU:"
top -bn1 | grep "Cpu(s)"
echo "Penggunaan Memori:"
free -h
echo "Ruang Disk:"
df -h
#!/bin/bash
# Script pengecekan koneksi internet
ping -c 4 google.com > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Koneksi Internet Tersambung"
else
echo "Koneksi Internet Terputus"
fi
#!/bin/bash
# Script update sistem
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
#!/bin/bash
# Script tambah pengguna baru
read -p "Masukkan nama pengguna: " username
read -sp "Masukkan password: " password
sudo useradd -m $username
echo "$username:$password" | sudo chpasswd
#!/bin/bash
# Script monitoring log
LOG_FILE="/var/log/syslog"
LINES=50
echo "--- $LINES Baris Terakhir Log ---"
tail -n $LINES $LOG_FILE
#!/bin/bash
# Script pembersih file temporary
TEMP_DIR="/tmp"
DAYS=7
find $TEMP_DIR -type f -mtime +$DAYS -delete
echo "File temporary lebih dari $DAYS hari telah dihapus"
#!/bin/bash
# Script backup database MySQL
DB_USER="username"
DB_PASS="password"
BACKUP_DIR="/path/to/backup"
DATE=$(date +"%Y%m%d")
mysqldump -u $DB_USER -p$DB_PASS --all-databases > $BACKUP_DIR/mysql_backup_$DATE.sql
#!/bin/bash
# Script pemantauan proses berlebihan
THRESHOLD=80
while true; do
top_cpu=$(ps aux | sort -nrk 3,3 | head -1)
cpu_usage=$(echo $top_cpu | awk '{print $3}')
if (( $(echo "$cpu_usage > $THRESHOLD" | bc -l) )); then
echo "Peringatan: Proses berlebihan terdeteksi!"
echo "$top_cpu"
fi
sleep 60
done
#!/bin/bash
# Script konfigurasi firewall sederhana
# Hapus semua aturan
iptables -F
# Blokir semua koneksi masuk
iptables -P INPUT DROP
iptables -P FORWARD DROP
# Izinkan koneksi loopback
iptables -A INPUT -i lo -j ACCEPT
# Izinkan koneksi yang sudah mapan
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Izinkan SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Catatan:
chmod +x script.sh./script.shSesuaikan script dengan kebutuhan spesifik Anda.
script untuk jaringn
Berikut adalah beberapa script Linux untuk keperluan jaringan:
#!/bin/bash
# Script pengecekan koneksi jaringan
# Daftar host untuk dicek
HOSTS=("google.com" "8.8.8.8" "facebook.com")
echo "=== Pengecekan Koneksi Jaringan ==="
for host in "${HOSTS[@]}"; do
ping -c 4 $host > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$host: Tersambung ✓"
else
echo "$host: Tidak Tersambung ✗"
fi
done
# Informasi IP dan Interface
echo -e "\n=== Informasi Jaringan ==="
ip addr show
#!/bin/bash
# Script monitoring bandwidth
INTERFACE="eth0" # Sesuaikan dengan interface jaringan Anda
echo "=== Monitoring Bandwidth Real-time ==="
# Menggunakan iftop untuk monitoring
sudo iftop -i $INTERFACE
#!/bin/bash
# Script scanning port
read -p "Masukkan alamat IP: " IP
read -p "Masukkan rentang port (contoh 1-100): " PORT_RANGE
echo "=== Scanning Port ==="
nmap -p $PORT_RANGE $IP
#!/bin/bash
# Script konfigurasi IP statis
# Konfigurasi variabel
INTERFACE="eth0"
IP_ADDRESS="192.168.1.100"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
# Konfigurasi IP
sudo nmcli con mod $INTERFACE ipv4.addresses $IP_ADDRESS/$NETMASK
sudo nmcli con mod $INTERFACE ipv4.gateway $GATEWAY
sudo nmcli con mod $INTERFACE ipv4.dns "$DNS1 $DNS2"
sudo nmcli con mod $INTERFACE ipv4.method manual
# Restart network
sudo nmcli con up $INTERFACE
#!/bin/bash
# Script speedtest jaringan
echo "=== Speedtest Jaringan ==="
# Pastikan speedtest-cli sudah terinstall
# Install dengan: sudo pip3 install speedtest-cli
speedtest-cli --simple
#!/bin/bash
# Script monitoring koneksi SSH
echo "=== Daftar Koneksi SSH Aktif ==="
# Menampilkan koneksi SSH
who
echo -e "\n=== Detail Koneksi SSH ==="
last | grep "still logged in"
#!/bin/bash
# Script backup konfigurasi jaringan
BACKUP_DIR="/home/user/network_backup"
DATE=$(date +"%Y%m%d")
# Buat direktori backup
mkdir -p $BACKUP_DIR
# Backup file konfigurasi jaringan
cp /etc/netplan/*.yaml $BACKUP_DIR/netplan_$DATE.yaml
cp /etc/network/interfaces $BACKUP_DIR/interfaces_$DATE
cp /etc/resolv.conf $BACKUP_DIR/resolv_$DATE.conf
echo "Backup konfigurasi jaringan selesai di $BACKUP_DIR"
#!/bin/bash
# Script monitoring koneksi aktif
echo "=== Koneksi Jaringan Aktif ==="
# Menampilkan koneksi TCP dan UDP
ss -tunap
#!/bin/bash
# Script konfigurasi firewall
# Reset aturan firewall
iptables -F
iptables -X
# Set default policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
# Izinkan koneksi loopback
iptables -A INPUT -i lo -j ACCEPT
# Izinkan koneksi yang sudah mapan
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Izinkan SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Izinkan HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Simpan konfigurasi
sudo service iptables save
#!/bin/bash
# Script traceroute otomatis
# Daftar host untuk traceroute
HOSTS=("google.com" "cloudflare.com" "microsoft.com")
echo "=== Traceroute Otomatis ==="
for host in "${HOSTS[@]}"; do
echo -e "\nTraceroute ke $host:"
traceroute $host
done
Catatan Penting:
chmod +x script.sh./script.shTips Instalasi Paket Pendukung:
# Untuk Ubuntu/Debian
sudo apt update
sudo apt install net-tools nmap speedtest-cli
Semoga membantu! Script-script ini dapat disesuaikan lebih lanjut sesuai kebutuhan jaringan Anda.