From 5a8f3bc36519cfdc56c030860ce120a77f23d9cd Mon Sep 17 00:00:00 2001 From: Adrian Wood Date: Sun, 10 Aug 2025 22:10:21 +0100 Subject: [PATCH] Uploaded initial script A script which creates a RAMdisk, copies the contents of the current directory to it, and runs a command of your choice in that RAMdisk copy of the data. Once the command is complete, the RAMdisk contents are synced back to the original directory. This allows commands to be performed on a directory at the lowest possible latency regardless of the locations of the files, at the expense of start/end time to swop the entire contents or the file system into memory, and the associated RAM requirement to store the files. Usage: $0 Example: $0 1G dosbox Signed-off-by: Adrian Wood --- runram | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 runram diff --git a/runram b/runram new file mode 100644 index 0000000..0dbb281 --- /dev/null +++ b/runram @@ -0,0 +1,32 @@ +#!/bin/bash + +if [ $# = "2" ]; then + + RAMDISK_SIZE="$1" + PROGRAM_PATH="$2" + ORIG_PATH="${PWD}" + RAMDISK_MOUNT="/mnt/ramdisk" + + if [ ! -d "$RAMDISK_MOUNT" ]; then + sudo mkdir -p "$RAMDISK_MOUNT" + sudo mount -t tmpfs -o size="$RAMDISK_SIZE" tmpfs "$RAMDISK_MOUNT" + fi + + cp -r ./* "$RAMDISK_MOUNT" + + cd "$RAMDISK_MOUNT" + "$PROGRAM_PATH" + + cd "$ORIG_PATH" + rsync -av --delete "$RAMDISK_MOUNT/" "$ORIG_PATH" + + if mountpoint -q "$RAMDISK_MOUNT"; then + sudo umount "$RAMDISK_MOUNT" + sudo rmdir "$RAMDISK_MOUNT" + fi +else + echo "Not enough arguments" + echo "Usage $0 " + echo "Example: $0 1G dosbox" + exit 1 +fi \ No newline at end of file