Yani temelde bu betiğin yapmasını istediğim, örneğin her 300 saniyede bir dosyanın kopyasını çıkarmak, ancak bir "savegame.backup1" dosyası oluşturmak ve sonra bir sonraki 300 saniye "savegame.backup2" ve ardından geri dönmek arasında geçiş yapmak backup1'a.
Zamanlayıcım tekrar ediyor gibi görünüyor ve bu betiği nasıl tamamlayabileceğimden emin değilim.
Bağlam için, kullandığım kodun çoğu googling'di, bazıları kişisel bilgilerimle yapıldı. Eksik olanı bulamıyorum.
Teşekkürler
#!/bin/bash
GameType="Sandbox" #Sandbox, Survival, etc.
SaveName="07-01-2017_04-52-11" #Make sure you copy the folder name.
Timeout=$((5)) #Timeout in seconds. The default of 300 (5 minutes) is likely adequate.
#No need to change anything below.
GameName="Project Zomboid"
SERVICE=ProjectZomboid64 #Change this to ProjectZomboid32 if you're using 32bit java!
steam steam://rungameid/108600
# Checks to see if folder exists - if not, one will be made.
mkdir -p "$HOME/Zomboid/Saves/Backups/$SaveName"
#Loop start
while [ $Timeout -gt 0 ]; do
clear && echo -ne "Creating a backup in" $Timeout "seconds."
sleep 1
: $((Timeout--))
done
clear
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
cp "$HOME/Zomboid/Saves/$GameType/$SaveName/map_p.bin" "$HOME/Zomboid/Saves/Backups/$SaveName/map_p.bin.backup1"
#Need to alternate between the two each time it loops. Backup1 the first time, Backup2 the second, Backup1 the third...
#cp "$HOME/Zomboid/Saves/$GameType/$SaveName/map_p.bin" "$HOME/Zomboid/Saves/Backups/$SaveName/map_p.bin.backup2"
echo "$GameName is running. Backup made." #ERROR CHECKING
else
#Loop should end here, and prevent any further repeating of the loop.
read -r -p "$GameName is not detected as running, and no further backups will be made."
fi
echo "Outside of loop." #ERROR CHECKING
sleep 5s
Peki, sorunu çözmek için şu ana kadar ne denediniz ve sonuçlar neydi? İlk öneri: Bash'de bir While döngüsünün nasıl oluşturulduğuna dair sözdizimini tekrar kontrol etmelisiniz.
—
Ƭᴇcʜιᴇ007
@ TECHIE007 Döngünün dışına başka bir döngü eklemeye çalıştım ve ardından döngü içinde başka bir döngü eklemeye çalıştım. Bu yüzden loop1 = sonsuz, loop1'in içindeki loop2 ve ardından loop2'nin içindeki loop3. Verilen cevap işe yaradı. İşte şimdi sahip olduğum şey: pastebin.com/yk8k8Yxh ama şimdi tek ihtiyacım $ $ 'ı her geçişte +1 ekleyerek $ $' a dönüp $ BackupCount değerine ulaşıp kendini sıfırlamak.
—
Interknet
Oh ve sonuçlar karışıktı. Kod eklemek için bulduğum şeyler, bunları uyguladığımda işe yaramadı. Yine de öğreniyorum: D
—
Interknet