Script Run as systemd Service won't Read CSV Properly
-3
votes
1
answer
56
views
I have a script to backup game saves from the Steam Deck to a network drive. It works perfectly when I run it on its own. However, when I configure it to run as systemd service at startup, for whatever reason it refuses to read a csv file needed to configure the script. Again, this ONLY happens when run as a service. The service WILL work if I change the current directory in the script to the directory of the csv file (also where the script is located), but then on my next reboot it causes my samba network drive mount to break for some reason. I'm so confused and frustrated, please help.
CODE SECTION IN QUESTION:
...
### Manually set script directory
#SCRIPT_DIR=/home/deck/Documents/scripts/SyncSaves
SCRIPT_DIR=~/Documents/scripts/SyncSaves
## If I force the current directory to script directory, it works, but when I reboot my mount to the network drive 'xtra' is broken (which is needed for the script).
### -> cd $SCRIPT_DIR
# Here is where we read the csv file
echo "READING GAMES DATABASE FROM SCRIPT_DIR: "
exec /dev/null; then
if [ "$DIFFS" == "" ]
then
echo "No Backups Needed: $full_path";
else
echo "backing up previous backups..."
rsync --update -va --exclude $exclude_files $backup_path1 $backup_path2
echo "backing up previous saves..."
rsync --update -va --exclude $exclude_files $full_cloud_path $backup_path1
echo "backing up current saves..."
rsync --update -va --exclude $exclude_files $full_path $full_cloud_path
fi
elif [ "$op" == "-update" ]
then
if [ $backup_only == 1 ]
then
echo "..."
echo "$game_name is set to backup ONLY"
echo "..."
else
echo "updating current saves..."
rsync --update -va --exclude $exclude_files $full_cloud_path $full_path
fi
else
echo "ERROR: Unknown Operation"
fi
fi
echo ""
else
echo "-$a not found, skipping: $full_path"
echo ""
fi
done > $SCRIPT_DIR/sync_saves.log
LOG_PATH="${lin_cloud_drive}${cloud_path}/sync_saves.log"
LOG_PATH=$(echo $LOG_PATH | sed -r 's|\\\\|\\|g')
LOG_PATH=$(echo $LOG_PATH | sed -r 's/\\/\//g')
#SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE}" )" &> /dev/null && pwd )
#$echo "Script is located in: $SCRIPT_DIR"
echo "Writing to log at $LOG_PATH"
echo "Last sync - $op - by $USER on $(date) - TESTING: $TESTING" >> $LOG_PATH
if $TESTING; then
echo TESTING MODE ON - FILES WERE NOT SYNCED...
fi
echo SAVES SYNCHRONIZED
echo "################################################################"
exit
SERVICE (SHOULD BE FINE, BUT INCLUDING JUST IN CASE):
[Unit]
Description=SyncSaves Startup
Requires=home-deck-mnt-xtra.mount
After=home-deck-mnt-xtra.mount
[Service]
Type=oneshot
#ExecStart=/home/deck/Documents/scripts/svc_test/svc_test.sh
ExecStart=/home/deck/Documents/scripts/SyncSaves/update_and_sync.sh
[Install]
WantedBy=default.target
This is set up as a user service, not a system service. I'm not sure if it is possible or advisable to create a system service on SteamOS.
Asked by imfm
(15 rep)
Aug 21, 2024, 12:12 AM
Last activity: Aug 21, 2024, 04:25 AM
Last activity: Aug 21, 2024, 04:25 AM