[Solved] Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
[Solved] Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Hi, this is a Linux question per-se and not Mint-specific.
I am using Resilio Sync to sync files with my home NAS, I actively use my NAS as my personal cloud game save service for syncing the DOSBOX and Windows 9x-era game saves across my laptops and desktop for continue playing my favourite games wherever I am.
For most DOS games, I can simply save the whole game directory in my NAS and a local directory in my active system, and whenever I save a game, it automatically saved in the synced directory which will update the savegame file into my NAS.
For larger games and those games which have a separate savegame directory, it is easy to upload only the savegame folder. But some games save the files directly into the working directory and I don't want to upload the whole directory to my NAS to sync only the savegame files.
I would like to create a bash script for use with my savegame files, and here is what I would like to do:
The game ( now in question, is Quest for Glory 2 VGA remake by AGDI) saves the savegame files directly into the working directory.
I would like to create a bash script to check any newly created save files and move them to my NAS-synced local folder, and then soft link these files back into my working game directory.
How can I go about accomplishing this task? (I know how to soft link, but would like to know how to detect new save game files every time the game creates and only move these latest files to the NAS synced folder and soft link them back?
I don't want to test for and move the already synced previous save games. Only the new one.
I can run the script once I exit the game.
For easy readability :
1. Detect if any new save game files has been created. (The game saves in a fixed format - agssave.001.Qfg2sav, agssave.002.Qfg2Sav... and so on.)
2. Move it/them to my NAS-synced local directory.
3. Soft link back these newly created files back to the working game directory.
4. Don't touch already synced save game files created before. (They are already being synced.)
Thank you for any help!
Cheers.
I am using Resilio Sync to sync files with my home NAS, I actively use my NAS as my personal cloud game save service for syncing the DOSBOX and Windows 9x-era game saves across my laptops and desktop for continue playing my favourite games wherever I am.
For most DOS games, I can simply save the whole game directory in my NAS and a local directory in my active system, and whenever I save a game, it automatically saved in the synced directory which will update the savegame file into my NAS.
For larger games and those games which have a separate savegame directory, it is easy to upload only the savegame folder. But some games save the files directly into the working directory and I don't want to upload the whole directory to my NAS to sync only the savegame files.
I would like to create a bash script for use with my savegame files, and here is what I would like to do:
The game ( now in question, is Quest for Glory 2 VGA remake by AGDI) saves the savegame files directly into the working directory.
I would like to create a bash script to check any newly created save files and move them to my NAS-synced local folder, and then soft link these files back into my working game directory.
How can I go about accomplishing this task? (I know how to soft link, but would like to know how to detect new save game files every time the game creates and only move these latest files to the NAS synced folder and soft link them back?
I don't want to test for and move the already synced previous save games. Only the new one.
I can run the script once I exit the game.
For easy readability :
1. Detect if any new save game files has been created. (The game saves in a fixed format - agssave.001.Qfg2sav, agssave.002.Qfg2Sav... and so on.)
2. Move it/them to my NAS-synced local directory.
3. Soft link back these newly created files back to the working game directory.
4. Don't touch already synced save game files created before. (They are already being synced.)
Thank you for any help!
Cheers.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
I think this should be relatively easy to do. Because you know that the previously synced files are going to be symlinks, you should be able to use the find command and limit it to actual files and those will be the new save games.
I think something like this would work:
-type f in the find command limits your search to only files and will ignore symlinks. The *.Qfg2sav should only search for the format of the save game files.
Obviously you would need to change the /path/to/QFG2Folder and the /path/to/NAS paths to be the location of the actual directories you want.
I think something like this would work:
Code: Select all
#!/bin/bash
for f in $(find /path/to/QFG2Folder/*.Qfg2sav -type f );
do
FILENAME="$(basename "$f")"
mv "$f" /path/to/NAS
ln -s /path/to/NAS/"$FILENAME" /path/to/QFG2Folder
done
Obviously you would need to change the /path/to/QFG2Folder and the /path/to/NAS paths to be the location of the actual directories you want.
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Hi thanks for the help. I'm facing an error.
Here's my savetocloud.sh:
Error is
The filename is (Copy and paste directly to avoid typing errors.)
I have tried creating a dummy savefile with the same nomenclature with the next in sequence 004, just in case the script couldn't find a fresh made file, but it still showed no such file or directory.
Here's my savetocloud.sh:
Code: Select all
#!/bin/bash
for f in $(find '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II/*.Qfg2Sav' -type f );
do
FILENAME="$(basename "$f")"
mv "$f" '/run/media/malik/FILES/Syncloud/Game Saves Cloud/QFG2VGA/'
ln -s '/run/media/malik/FILES/Syncloud/Game Saves Cloud/QFG2VGA/'"$FILENAME" '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II/'
done
Code: Select all
find: '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II/*.Qfg2Sav': No such file or directory
Code: Select all
agssave.001.Qfg2Sav
I have tried creating a dummy savefile with the same nomenclature with the next in sequence 004, just in case the script couldn't find a fresh made file, but it still showed no such file or directory.
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
It's the quotes around
.../*.Qfg2Sav
: you are with them asking find to search for that exact file, i.e., the file named .../*.Qfg2Sav
; the quotes remove the meaning of *
as a wildcard. I.e., quote as for exampleCode: Select all
for f in $(find '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/*.Qfg2Sav -type f);
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Hmm...seems like the nomenclature of my spaced-naming directories are interfering with the command.
Here's the output now after adjusting the quote location:
And what it does now is create broken symlinks of the 'AGD', 'Quest', 'for', 'Glory', 'Program' and 'Files' directories in the working directory.
Surprisingly 'Interactive' is not made into a broken symlink directory.
Here's the output now after adjusting the quote location:
Code: Select all
mv: cannot stat '/home/malik/.wine/drive_c/Program': No such file or directory
mv: cannot stat 'Files': No such file or directory
mv: cannot stat '(x86)/AGD': No such file or directory
mv: cannot stat 'Interactive/Quest': No such file or directory
mv: cannot stat 'for': No such file or directory
mv: cannot stat 'Glory': No such file or directory
Surprisingly 'Interactive' is not made into a broken symlink directory.
-
- Level 16
- Posts: 6054
- Joined: Mon Aug 27, 2012 10:17 pm
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Escape the spaces like this:
Code: Select all
for f in $(find '/home/malik/.wine/drive_c/Program\ Files\ (x86)/AGD\ Interactive/Quest\ for\ Glory\ II/*.Qfg2Sav' -type f );
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
The immediately above is not going to work; the single quotes also remove special meaning of \. And, oh, yes, crap; had noticed you quoted
i.e., with an additional "-pair around the entire
[EDIT] Yes, that would work:
"$f"
so glanced over it otherwise, but the find itself is now still providing the loop with the space-seperated values. Try it asCode: Select all
for f in "$(find '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/*.Qfg2Sav -type f)";
$(find ...)
. Should work it seems. Pardon if I miss something again; while I'm personally quite keen on NOT deprecating spaces in filenames ("the computer adapts to the human, not the other way around.") they can admittedly make for a bit of a confusing mess as to needing quoting on the command line.[EDIT] Yes, that would work:
Code: Select all
rene@hp8k:~$ mkdir -p '.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'
rene@hp8k:~$ touch '.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/foo.Qfg2Sav
rene@hp8k:~$ touch '.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/bar.Qfg2Sav
rene@hp8k:~$ for f in "$(find '.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/*.Qfg2Sav -type f)"; do echo "$f"; done
.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II/bar.Qfg2Sav
.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II/foo.Qfg2Sav
Re: Help for bash script to move savegames created by a game to my personal cloud and make a soft link back.
Yes! This did it! Thank you so much!rene wrote: ⤴Tue Apr 13, 2021 5:00 am The immediately above is not going to work; the single quotes also remove special meaning of \. And, oh, yes, crap; had noticed you quoted"$f"
so glanced over it otherwise, but the find itself is now still providing the loop with the space-seperated values. Try it as
i.e., with an additional "-pair around the entireCode: Select all
for f in "$(find '/home/malik/.wine/drive_c/Program Files (x86)/AGD Interactive/Quest for Glory II'/*.Qfg2Sav -type f)";
$(find ...)
. Should work it seems. Pardon if I miss something again; while I'm personally quite keen on NOT deprecating spaces in filenames ("the computer adapts to the human, not the other way around.") they can admittedly make for a bit of a confusing mess as to needing quoting on the command line.
[EDIT] Yes, that would work:
The mess a misplaced quote makes...
Thanks for chiming in too, Kadaitcha!
-
- Level 16
- Posts: 6054
- Joined: Mon Aug 27, 2012 10:17 pm