Two questions: Automatic Log backup script and MySQL password reset

Source: Internet
Author: User
Tags pkill rsyslog

========================================================== ==========
This article isHeyuanhuiOriginal

Make sure that the original author information and original links of this article are complete and retained!

NN: khler
E-mail:Khler@163.com
QQ: 23381103
MSN:Pragmac@hotmail.com
========================================================== ==========

 

Recently, a service named TWS is implemented in Linux. It outputs logs using Syslog and uses MySQL as the background database. I encountered two problems here, and the waste was quite a bit (I was very impressed :)...) it takes a long time to solve the problem. Now it is recorded here. I hope to help my friends who have the same problems and save valuable time.

I. log output and automatic backup script:

Through the cron service, we can execute scripts on a regular basis. Here, of course, we execute twslogbaker on a regular basis every day. sh script to back up the log information generated by my TWS. I put it in the same directory as the executable file of the TWS service. This is of course a common directory, the result is depressing that it is okay to manually execute this script. During cron scheduled execution, syslogs cannot be newly generated TWS. write information in the log file...

The specific method is:

1. Output logs:

In my TWS service, openlog ("TWS", log_ndelay, log_user) is called at startup; closelog () is called before exit; intermediate output log is syslog (log_info | log_local6, "% s", buff );

Then add the. conf file under/etc/syslog. conf (for Ubuntu, add the. conf file under/etc/rsyslog/. For details, refer to the rsyslog document of ubuntu)

TWS. */usr/local/twslog/TWS. Log

2. Scheduled Backup:

Add: 59 23 *** root/usr/sbin/twslogbaker to/etc/crontab. sh, so that the script twslogbaker under/usr/sbin/is executed every night. sh.

The twslogbaker. Sh script is used to back up TWS. Log logs. The script content is as follows:

 

#! /Bin/sh

# Current date
Currdate = $ (date + % Y-% m-% d)

# Log Path
Path = "/usr/local/twslog"

# Original file
Orgfile = "TWS. log"

# New File
Dailyfile = "$ currdate. log"

Echo "---> Log Path: '$ path '"
Echo "---> starting Bak '$ orgfile' to '$ dailyfile '..."

# Is 'tws. log' file exist?
# If [! -R $ logfile]
If [-r $ path/$ orgfile]
Then
# Bake up Log File
Echo "---> rename' $ orgfile 'to' $ dailyfile '"
MV $ path/$ orgfile $ path/$ dailyfile
Else
Echo "---> File '$ orgfile' not exist! "
Fi

# Empty TWS. Log
# Echo "---> Create '$ orgfile 'file"
Touch $ path/$ orgfile
# Chown root $ path/$ orgfile
Chmod 666 $ path/$ orgfile echo "---> done! "
 

 

 

Twslogbaker. the sh script is placed under/usr/sbin/. As a result, syslogs cannot be uploaded to the new TWS after backup. write the content in the log file and put it in/usr/sbin/. Is it because of permission issues? It's not clear yet. Let me explain it to you.

 

Ii. Reset the password of MySQL:

Refer to this article:

Http://sundful.javaeye.com/blog/704337

  ReferenceMySQL error 1045 (28000): Access denied for user 'root' @ 'localhost' Solution

To solve this problem, you need to force a new password. The method is as follows:

/Etc/init. d/MySQL stop (Service mysqld stop)
/Usr/bin/mysqld_safe -- skip-grant-tables
Enable another SSH connection
[Root @ localhost ~] # MySQL
Mysql> use MySQL
Mysql> Update user SET Password = PASSWORD ("123456") where user = "root ";
Mysql> flush privileges;
Mysql> exit

Pkill-kill-T pts/0: force the ** users whose PTS is 0 (the user window before mysqld_safe is run) out.
Start MySQL normally:/etc/init. d/MySQL start (Service mysqld start)

Note: In addition, service MySQL star is required to start service MySQL stop before it can be stopped.
The command cannot be found directly using MySQL. The error is "Bash: mysql: Command not found". You can run the command directly in the bin folder and absolute path in the MySQL installation directory, also need to add. /MySQL can be executed.

 

The last step is when pkill. You must note that the first step you open is not necessarily pts/0, it may be PSt/1, PSt/2 ..., therefore, the safest way is to close the command window directly. I may not run the command correctly during the previous pkill operation, so that I cannot log on After resetting the password. The same "MySQL error 1045 (28000 ): access denied for user 'root' @ 'localhost' problem "makes my head big...

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.