LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2012, 04:14 AM   #1
Freddy49
LQ Newbie
 
Registered: Oct 2012
Location: US
Distribution: Fedora
Posts: 6

Rep: Reputation: Disabled
Post Compress and append date to a file using PHP


Hello


I am trying to do the Following;


1. copy messages from /var/log/ to /scratch this works.

2. append the date to the messages file in /scratch, not the original File so it looks like messages_date

3. zip the messages_date file, so it looks like messages_date.zip

4. upload the messages_date.zip file



Here is my Code (it uploads the File, with NO data)

$ORIGINAL_MESSAGES='messages';
$TIME_STAMP=date("mdYHis");
$NEW_MESSAGES="$ORIGINAL_MESSAGES" . "$TIME_STAMP";



chdir("/var/log");
if (file_exists($ORIGINAL_MESSAGES))
{
echo "file EXISTS, . $ORIGINAL_MESSAGES . coping to /scratch\n\n";
copy($ORIGINAL_MESSAGES, "/scratch/$NEW_MESSAGES");
chdir("/scratch");
}else{
echo ("file Does Not Exist");
}



chdir("/scratch");
if (file_exists($NEW_MESSAGES))
{
echo("\n\nfile EXISTS\n\n compressing file");
system("zip -9 -r -y -q $NEW_MESSAGES.zip . -i $NEW_MESSAGES");

}else{
echo ("file Does Not Exist");



//set up basic connection
$GPS = ftp_connect($FTP_SITE) or die("Couldn't connect to $GPS");

if (@ftp_login($GPS, $USERNAME, $PASS_WORD)) {
echo "\n\nConnected as $USERNAME \n\n";
} else {
echo "\n\nCouldn't connect as $USERNAME\n";
}


ftp_mkdir($GPS, "$REMOTE_DIR");
ftp_chdir($GPS, "$REMOTE_DIR");
chdir('/scratch');
ftp_put($GPS, "$NEW_MESSAGES.zip", "$NEW_MESSAGES.zip", FTP_BINARY);
echo "File(s) uploaded successfully $NEW_MESSAGES.zip ";


echo '</pre>';

ftp_close($GPS);
 
Old 11-05-2012, 12:17 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
What is the overall goal you're trying to accomplish? Are you trying to centralize logs to a single server?
 
Old 11-05-2012, 12:47 PM   #3
Freddy49
LQ Newbie
 
Registered: Oct 2012
Location: US
Distribution: Fedora
Posts: 6

Original Poster
Rep: Reputation: Disabled
Post

I want to have important log files time stamped and copied to a directory. Then have the files zipped up one by one and then sent to a FTP site for review.

So example. Copy messages file to a temp dir. Then have the file renamed to messages-date. Then compressed messages-date.zip. The. Uploaded to a FTP server.

Fred
 
Old 11-05-2012, 01:03 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
There's easier ways of doing this using syslog/rsyslog and syslog-ng. You can then easily filter the centralized logs and have them emailed to you. It is easy to create a filtered hourly or daily digest for email.
 
Old 11-05-2012, 01:12 PM   #5
Freddy49
LQ Newbie
 
Registered: Oct 2012
Location: US
Distribution: Fedora
Posts: 6

Original Poster
Rep: Reputation: Disabled
Post

I can't do this that way. The servers that I want to do this for is not on the same network. It needs to use FTP.
 
Old 11-05-2012, 01:24 PM   #6
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by Freddy49 View Post
I can't do this that way. The servers that I want to do this for is not on the same network. It needs to use FTP.
They don't need to be on the same network and can easily be secured with TLS (though FTP itself is insecure so not sure that's really the issue). If you can access the remote server gathering logs using FTP then it should be conceivable to access it using any other protocol. That being said I guess I'll let others directly answer your original question. I still think it is better to rely on proven solutions where it has been battle tested.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to append data to a file with php/fwrite steve51184 Linux - Server 2 08-16-2010 08:35 PM
How can I append the date/time stamp to commands in history? abefroman Linux - Security 2 05-29-2008 11:21 AM
script to change file name and append the date john_551 Linux - Software 4 08-26-2006 06:56 AM
php read file creation, modified date problem antony_csf Programming 3 08-18-2004 06:46 AM
How to append today's date in a script anjaan Programming 4 06-12-2004 08:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration