akiratheoni
August 7th, 2008, 09:16 AM
I'm an admin on a forum that needs a bash script that'll be used on a crontab.
Here's the scenario... the file structure looks like this:
exchange/backups/
exchange/backups/sites_0:00_8-01-08.txt
exchange/backups/sites_1:00_8-01-08.txt
exchange/backups/sites_2:00_8-01-08.txt
exchange/backups/sites_3:00_8-01-08.txt
exchange/sites.txt
exchange/admin.php
exchange/index.php
As you can see, the sites.txt in the exchange/ folder is backed up hourly.
Now, for some reason there's an error in the index.php file (not quite sure what it is) that renames the sites.txt to sites_.txt and thus breaks everything >.<
When the sites.txt is renamed to sites_.txt, everything in the sites.txt is lost and it's a blank file.
So basically I need to code a script that every hour it will check if "sites_.txt" exists, and if it does, restore the most recent sites.txt back up and delete the sites_.txt
I was only able to create a bash script that would back up sites.txt... I'm a complete noob at bash scripting. And this is completely out of my league, I have no idea how to do this.
It would be great though if someone did this and if they explained what each line does (it's not necessary though... but I do want to learn bash scripting)
Thanks everyone. If this is in the wrong forum, move it to the appropriate one :P thanks. If there's any questions or any confusion, please ask them and I'll clear it up so you can help.
Here's the scenario... the file structure looks like this:
exchange/backups/
exchange/backups/sites_0:00_8-01-08.txt
exchange/backups/sites_1:00_8-01-08.txt
exchange/backups/sites_2:00_8-01-08.txt
exchange/backups/sites_3:00_8-01-08.txt
exchange/sites.txt
exchange/admin.php
exchange/index.php
As you can see, the sites.txt in the exchange/ folder is backed up hourly.
Now, for some reason there's an error in the index.php file (not quite sure what it is) that renames the sites.txt to sites_.txt and thus breaks everything >.<
When the sites.txt is renamed to sites_.txt, everything in the sites.txt is lost and it's a blank file.
So basically I need to code a script that every hour it will check if "sites_.txt" exists, and if it does, restore the most recent sites.txt back up and delete the sites_.txt
I was only able to create a bash script that would back up sites.txt... I'm a complete noob at bash scripting. And this is completely out of my league, I have no idea how to do this.
It would be great though if someone did this and if they explained what each line does (it's not necessary though... but I do want to learn bash scripting)
Thanks everyone. If this is in the wrong forum, move it to the appropriate one :P thanks. If there's any questions or any confusion, please ask them and I'll clear it up so you can help.