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 <ramdisk_size> <program_path> Example: $0 1G dosbox Signed-off-by: Adrian Wood <ade@adeserv.uk>
This commit is contained in:
@@ -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 <ramdisk_size> <program_path>"
|
||||
echo "Example: $0 1G dosbox"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user