|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Thursday, 02 September 2010 18:34 |
|
Here's a little PHP command line script to do Apache Log Rotation on your web server. This script uses zip to compress the files and retains the logs for 10 days before deletion.
<?php date_default_timezone_set('America/New_York'); $starttime=date('G:i:s', strtotime('now')); $curDate=date("Ymd",strtotime('now')); $sitepath=array("/path/to/website1/log","/path/to/website2/log","/path/to/website3/log");
echo "Starting log rotation...\r\n";
echo "Moving current and removing obsolete logs ...\r\n\r\n"; foreach ($sitepath as $value) { system("mv ".$value."/access_log ".$value."/access_log.old", $retval); echo $retval."\r\n"; system("mv ".$value."/error_log ".$value."/error_log.old", $retval); echo $retval."\r\n"; $dir=opendir($value); while (false !== ($file = readdir($dir))) { $filepref=substr($file,0,8); if ($filepref<=date('Ymd',strtotime("-10 days")) && $filepref!="." && $filepref!="..") { unlink($value."/".$file); echo $value."/".$file." removed.\r\n"; } } closedir($dir); }
echo "Restarting Apache ...\r\n\r\n"; system("/etc/init.d/httpd graceful"); sleep(300);
echo "Archiving old logs ...\r\n\r\n"; foreach ($sitepath as $value) { system("zip -9 ".$value."/".$curDate."-access_log.zip ".$value."/access_log.old", $retval); echo $retval."\r\n"; system("rm ".$value."/access_log.old", $retval); system("zip -9 ".$value."/".$curDate."-error_log.zip ".$value."/error_log.old", $retval); echo $retval."\r\n"; system("rm ".$value."/error_log.old", $retval); }
$endtime=date('G:i:s',strtotime('now')); echo "\r\nStart time - ".$starttime."\r\n"; echo "End time - ".$endtime."\r\n\r\n"; echo "Script complete!\r\n"; ?>
|
|
|
Tech Notes -
General
|
|
Written by Rick
|
|
Tuesday, 25 May 2010 10:23 |
|
I ran across a situation where Apache wouldn't start. It generated the following error;
"(98)address already in use: make_sock: could not bind to address [::]:80 (98)address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down unable to open logs"
I located a thread at wallpaperama.com that fixed the problem. Use the following from CLI;
First;
for i in `ps auwx | grep -i nobody | awk {'print $2'}`; do kill -9 $i; done
Second;
for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done
If Apache still doesn't start;
for i in `ipcs -s | grep nobody | awk '{print $2}'`; do ipcrm -s $i; done
Correcting my particular problem did not require running the last line.
|
|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Tuesday, 18 May 2010 17:47 |
|
My system at work had been acting funky for months. Every now and again, the monitor would go non-linear and I'd get no response from the mouse or keyboard. It would normally still be accessible remotely. So, I'd just reboot it that way and move on. I was pretty sure it was a memory or video card issue. But, I read where Ubuntu had some problems with the NVidia cards. I figured I'd wait 'til Ubuntu released 10.04 and do a fresh install.
|
|
Read more...
|
|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Tuesday, 06 April 2010 11:57 |
|
There is no command in MySQL to copy a database. One method to copy a database is as follows;
- Create a new empty database.
- Export the source database using mysqldump.
- Import the database to the new empty database created in step 1 above.
(See Linux CLI: MySQL Database Backup & Restore article for mysqldump usage).
Alternatively, phpMyAdmin can be used for small databases. More often-than-not, databases exceed size limits imposed by phpMyAdmin forcing CLI use or another method.
|
|
Tech Notes -
General
|
|
Written by Rick
|
|
Wednesday, 03 March 2010 00:00 |
|
It's not uncommon to run across a need to duplicate a database for testing purposes. PostgreSQL provides for the ability to duplicate the structure and data content with a single command;
CREATE DATABASE newdb WITH TEMPLATE originaldb;
With any luck it's obvious one needs to replace "newdb" with the new database name and "originaldb" with the name of the source database.
I've executed this command in phpPgAdmin (v4.2-beta-1) with success on a 657MB database. The process took approximately 10 minutes. I have no doubt the command can be executed from the pgsql prompt as well.
PostgreSQL DB Server version 8.1.11.
|
|
|
<< Start < Prev 1 2 3 Next > End >>
|
|
Page 1 of 3 |