/
noxit
/
DevOps_practices
Обзор
Документация
Войти
/
noxit
/
DevOps_practices
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
test
DevOps_snippets
106 строк
3 KB
kirill
fix_5sec
15 ноя 2025, 22:25
15 ноя 2025, 22:25
420c1d8
Код
Авторство
О чём код?
----------- Stop and remove all Docker containers docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) ----------- Monitor system logs in real-time tail -f /var/log/syslog ----------- Search for files containing specific text SEARCH_DIR="/path/to/search/directory" SEARCH_TEXT="search-text" grep -rl "${SEARCH_TEXT}" ${SEARCH_DIR} ----------- Add prefix to all files in a directory DIRECTORY="/path/to/directory" PREFIX="new_prefix_" for FILE in ${DIRECTORY}/* do mv ${FILE} ${DIRECTORY}/${PREFIX}$(basename ${FILE}) done ----------- Monitor log files for a certain pattern tail -f $LOG_FILE | grep $SEARCH_PATTERN ----------- Monitor system usage and resource consumption while true do clear echo "====== System Usage & Resource Consumption ======" echo "CPU Usage" echo "------------------------------------------------" top -b -n1 | head -10 echo " " echo "Free Memory" echo "------------------------------------------------" free -h echo " " echo "Disk Usage" echo "------------------------------------------------" df -h sleep 5 done ----------- Script to clean up old log files DIRECTORY="/var/log" DAYS=14 echo "Deleting log files older than $DAYS days in $DIRECTORY..." find "$DIRECTORY" -name "*.log" -type f -mtime +$DAYS -exec rm -f {} \; echo "Log files cleanup completed successfully." ----------- Script to backup a directory SOURCE="/path/to/source/directory" DESTINATION="/path/to/destination/directory" DATE=$(date +%Y-%m-%d) FILENAME="backup_$DATE.tar.gz" echo "Starting backup of $SOURCE to $DESTINATION/$FILENAME..." tar -czvf "$DESTINATION/$FILENAME" $SOURCE echo "Backup completed successfully." ----------- Show disks with high usage df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 " " $6 }' | while read output; do usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1) partition=$(echo $output | awk '{ print $2 }') mount_point=$(echo $output | awk '{ print $3 }') if [ $usage -ge 80 ]; then echo "Warning: Disk space usage on $partition ($mount_point) is at ${usage}%" fi done ----------- Restart Service systemctl restart $SERVICE_NAME ----------- Track Open Ports and Listening Services echo "Open Ports and Listening Services:" sudo netstat -tulpn | grep LISTEN ----------- Backup Files to Remote Server DATE=$(date +%Y%m%d) SOURCE_DIR="/path/to/source/directory" BACKUP_FILE="backup-$DATE.tar.gz" REMOTE_USER="remote_user" REMOTE_SERVER="remote_server" REMOTE_DIR="/path/to/remote/directory" tar -czvf $BACKUP_FILE $SOURCE_DIR scp $BACKUP_FILE $REMOTE_USER@$REMOTE_SERVER:$REMOTE_DIR rm -f $BACKUP_FILE echo "Backup completed and transferred to the remote server." ----------- Available free space on the system du -hsx /* | sort -rh | head -5