Log files


Hello, I am new to dreamhost. I want to store my access log files permanently in the server. Where do I set this? I can see a screen which allows me to define the number of days it can be saved, but I want to set it such a way that it will not be deleted.


I suggest you write a script to be executed by cron to copy your logs to somewhere within your account.


I don’t believe you can do this through the panel. As sigguested above, the best way to do this would be a script that copied out the files on a regular basis to a folder so they won’t get delted. Let us know if you need help writing said script - I’d be quite happy to help you out with that.



Matttail, I appreciate it. Please help me out. I am new to linux and also to dreamhost.


Sure thing, First off you’ll need a little background - You’re going to have to connect to your server through SSH and set up your Crontab. I’ll write the actual script to copy out the log files for you, but then you’ll have to upload it and set up the cronjob. So if you have a basic understanding it will help things along.

I should have the script finished up this evenning after classes.



I was wondering why you were interested in keeping the log files. I just wanted to mention that you might consider installing AW stats (instructions in the wiki) as I believe you can set it to store information - and then you’d have a graphical interface to access it through. Just an idea.



Ok, here’s the script. It took me a bit to get this one right, at first I thought I’d just use the date command and pull out the file. Then when I thought it through I realized that each day I’d have to copy out the previous days logs - as logs aren’t generated till then. The date command is an under documented utility, but with some help I figured out how to subtract one day from the current.

Any who, once you get this set up it will automatically copy out only the previous days access and error logs, to a directory where they won’t get deleted. The way I have the script right now it copies it to a folder called logs_store in your home directory - but you can have them copied anywhere you want.

Just copy and paste this into a simple text file - using note pad or the like. Make sure the commands don’t wrap. Save the file, for my example we’ll call it logs.sh. Upload the file to your home directory. Here’s the shell script:

DATE=date +%F -d "1 days ago"
cp /home/username/logs/domain.com/http/access.log.$DATE /home/username/logs_store
cp /home/username/logs/domain.com/http/error.log.$DATE /home/username/logs_store
exit 0

This script should be 5 lines long. You’ll need to replace username with the user who’s got control of the domain, and domain.com with the domain’s logs you want to backup. If you have more than one domain, simply duplicate each copy command appropriately.
Once you’ve got that we need to set up your cron job. You’ll have to log into SSH (see link above) and edit the crontab (again link above) put this line in:

  • 1 * * * /home/username/logs.sh

make sure there’s a blank line after your command. And again change out username for the user you put in above. press ctrl-o to save and ctrl-x to exit. You should get a message ‘success installing new crontab’

You’ll also need to create the logs_store directory. That’s in your home directory by my script. As I said before, if you want to you can change this to wherever you’d like.

Let me know if something doesn’t make sense.

I’ll go ahead and post this to the wiki tomorrow as well…