Skip to content

Instantly share code, notes, and snippets.

@SippieCup
Last active July 16, 2021 17:33
Embed
What would you like to do?
#!/bin/bash
ROOT_DIR=$1
DRIVE_NUM=$2
PORT=$3
printf -v DNAME "%02d" $DRIVE_NUM
cd $ROOT_DIR/$DNAME
echo Listening in $ROOT_DIR/$DNAME
next_dir () {
echo "in next_dir"
DRIVE_NUM=$((DRIVE_NUM+1))
printf -v DNAME "%02d" $DRIVE_NUM
echo switching dir to $ROOT_DIR/$DNAME
cd $ROOT_DIR/$DNAME
}
while true; do
nc -p $PORT -l | tar -x
echo "Plot saved in $ROOT_DIR/$DNAME"
ls plot-k32-2021-0[0-6]*.plot | head -n 1 | xargs rm -- || next_dir
done
@SippieCup
Copy link
Author

Usage: ./listener.sh ROOT_DIR DRIVE_NUMBER LISTENER_PORT

requires storage drives be named incrementally from 00 to 99.
ex:
/mnt/plots/00
/mnt/plots/01
/mnt/plots/02

example usage: ./listener.sh /mnt/plots 1 3001

Starts in folder /mnt/plots/01 and increments upwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment