Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # modified as PLC doesnt process *.bin files
- set -euo pipefail
- BASE="/media/eri/6634-6631/FCDATA01/DATALOG/1-secLog"
- START_DATE="20260401"
- CHUNK_MB=16
- RESERVE_MB=10000
- TMPFILE="/home/eri/Desktop/out.csv"
- # Create reusable file once
- if [[ ! -f "$TMPFILE" ]]; then
- echo "Creating temp file $TMPFILE (${CHUNK_MB} MB)..."
- dd if=/dev/zero of="$TMPFILE" bs=1M count="$CHUNK_MB" status=progress
- fi
- current="$START_DATE"
- while true; do
- current=$(date -d "${current} -1 day" +%Y%m%d)
- dir="$BASE/$current"
- mkdir -p "$dir"
- free_kb=$(df --output=avail "$BASE" | tail -n 1)
- free_mb=$((free_kb / 1024))
- usable_mb=$((free_mb - RESERVE_MB))
- if (( usable_mb <= 0 )); then
- echo "Stopping: not enough free space left."
- break
- fi
- outfile="$dir/file.csv"
- echo "Writing $outfile (${CHUNK_MB} MB)..."
- cp "$TMPFILE" "$outfile"
- done
- echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment