﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-aa19870406-随笔分类-Linux</title><link>http://www.cppblog.com/aa19870406/category/17000.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 19 Mar 2013 02:41:58 GMT</lastBuildDate><pubDate>Tue, 19 Mar 2013 02:41:58 GMT</pubDate><ttl>60</ttl><item><title>使用crontab自动化拷贝工作</title><link>http://www.cppblog.com/aa19870406/archive/2012/03/26/169053.html</link><dc:creator>MrRightLeft</dc:creator><author>MrRightLeft</author><pubDate>Mon, 26 Mar 2012 13:38:00 GMT</pubDate><guid>http://www.cppblog.com/aa19870406/archive/2012/03/26/169053.html</guid><wfw:comment>http://www.cppblog.com/aa19870406/comments/169053.html</wfw:comment><comments>http://www.cppblog.com/aa19870406/archive/2012/03/26/169053.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/aa19870406/comments/commentRss/169053.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/aa19870406/services/trackbacks/169053.html</trackback:ping><description><![CDATA[<p align="center" style="text-align:center"><span style="font-size:22.0pt;font-family:宋体;">使用</span><span style="font-size:22.0pt">crontab</span><span style="font-size:22.0pt;font-family:宋体;">自动化拷贝工作<br /></span><br /></p>    <p style="margin-left:43.1pt;text-indent:-36.0pt;"><strong><span style="font-size:16.0pt;">一、&nbsp;</span></strong><strong><span style="font-size:16.0pt;font-family: 宋体;">背景</span></strong><strong></strong></p>    <p><span style=" font-family:宋体;">由于开发机上缺少相应的环境，平时我们（特别是像我之类的新人）为了调试方便，往往会直接在测试机上进行开发工作，然后再拷贝到开发机上，提交到</span>svn<span style="font-family:宋体;">。然而这样会存在很多问题，有时候我们明明在测试机上测试正常，提测之后却出了问题，仔细检查可能会发现我们拷贝了文件到</span>svn<span style="font-family:宋体;">。避免这样的问题，一是在开发过程中，记录自己修改创建的文件，但这样比较繁琐；二是在开发机上开发，自测时使用测试机进行测试。毫无疑问第二种方法要好一些，但是这样往往会增加很多繁琐的拷贝工作，本文就是为了减少这样的工作而撰写。</span></p>  <h1><span style="font-size:16.0pt;">二、 </span><a href="http://my.oschina.net/aiguozhe/blog/33994"><span style="font-size:16.0pt; color:black;text-decoration:none;text-underline:none">SSH</span><span style="font-size:16.0pt; color:black;text-decoration:none;text-underline:none">免密码登录</span></a></h1>    <h1><span style="font-size:10.5pt; font-weight:normal;">我们首先要在测试机上建立免密码登陆开发机的信任关系。A为测试机(我的测试机是aaa@bbb.com); B为开发机(我的开发机是ccc@ddd.com); <br /> 在A上的命令: <br /> # ssh-keygen -t rsa (机器A上操作，连续三次回车,即在本地生成了公钥和私钥,不设置密码) <br /> # ssh ccc@ddd.com （机器A上操作，ssh登陆机器B时需要输入密码）<br /> # mkdir .ssh;chmod 700 .ssh （机器B上操作，如果.ssh目录存在，则不需要mkdir, 注:必须将.ssh的权限设为700) <br /> # scp ~/.ssh/id_rsa.pub ccc@ddd.com:/home/users/qinlei01/.ssh/id_rsa.pub(机器A上操作，需要输入密码) <br /> 登陆机器B，在B上的命令: <br /> # touch ~/.ssh/authorized_keys (如果已经存在这个文件, 跳过这条) <br /> # chmod 600 ~/.ssh/authorized_keys (# 注意： 必须将~/.ssh/authorized_keys的权限改为600, 该文件用于保存ssh客户端生成的公钥，可以修改服务器的ssh服务端配置文件/etc/ssh/sshd_config来指定其他文件名） <br /> # cat ~/.ssh/id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys (将id_rsa.pub的内容追加到 authorized_keys 中, 注意不要用 &gt; ，否则会清空原有的内容，使其他人无法使用原有的密钥登录) <br /> 回到A机器测试是否能免密码登陆机器B: <br /> # ssh ccc@ddd.com(不需要密码, 登录成功)<br /> =====================================================================<br /> <em><span style="font-family:宋体;">附上A与B互相免密码登陆的方法：</span></em><br /> <em><span style="font-family:宋体;">机器A：192.168.0.106</span></em><br /> <em><span style="font-family:宋体;">机器B：192.168.0.107</span></em><br /> <em><span style="font-family:宋体;">1</span></em><em><span style="font-family:宋体;">、在机器A上执行如下操作</span></em><br /> <em><span style="font-family:宋体;">ssh-keygen -d</span></em><br /> <em><span style="font-family:宋体;">然后一路回车</span></em><br /> <em><span style="font-family:宋体;">cd ~/.ssh</span></em><br /> <em><span style="font-family:宋体;">cp id_dsa.pub authorized_keys2</span></em><br /> <em><span style="font-family:宋体;">chmod 600 authorized_keys2</span></em><br /> <em><span style="font-family:宋体;">2</span></em><em><span style="font-family:宋体;">、在B上做如上同样的操作</span></em><br /> <em><span style="font-family:宋体;">3</span></em><em><span style="font-family:宋体;">、建立A到B的信任关系（即A免密码登陆B）</span></em><br /> <em><span style="font-family:宋体;">在A中执行（注意需要把文件改名）</span></em><br /> <em><span style="font-family:宋体;">scp id_dsa.pub usernameB@192.168.0.107:.ssh/a.pub</span></em><br /> <em><span style="font-family:宋体;">在B中的~/.ssh下执行</span></em><br /> <em><span style="font-family:宋体;">cat a.pub &gt;&gt; authorized_keys2</span></em><br /> <em><span style="font-family:宋体;">此时从A执行ssh到B就不用输入密码了</span></em><br /> <em><span style="font-family:宋体;">4</span></em><em><span style="font-family:宋体;">、建立B到A的信任关系（即B免密码登陆A）</span></em><br /> <em><span style="font-family:宋体;">在B执行</span></em><br /> <em><span style="font-family:宋体;">scp id_dsa.pub usernameA@192.168.0.106:.ssh/a.pub</span></em><br /> <em><span style="font-family:宋体;">在A执行</span></em><br /> <em><span style="font-family:宋体;">cat a.pub &gt;&gt; authorized_keys2</span></em><br /> <em><span style="font-family:宋体;">在配置过程需要输入多次密码</span></em><br /> <em><span style="font-family:宋体;">此时，无论从A到B，还是从B到A，都不需要输入密码了</span></em><br /> <em><span style="font-family:宋体;">如果出现问题，可以删除~/.ssh所有文件（连文件夹）,然后重新配置</span></em><br /> ====================================================================</span></h1>  <h1><span style="font-size:16.0pt;">三、建立拷贝文件脚本</span></h1>  <p>1<span style=" font-family:宋体;">、在机器</span>A<span style="font-family:宋体;">某路径建立拷贝文件脚本（如</span>/home/wiki/xx.sh<span style="font-family:宋体;">），在该</span>xx.sh<span style="font-family:宋体;">中加入自己需要从开发机上拷贝的文件。例如如下简单的</span>xx.sh<span style="font-family:宋体;">（要将</span>xx.sh<span style="font-family:宋体;">设定为可执行，可简单</span>chmod 777 xx.sh<span style="font-family:宋体;">）</span></p>  <p>  <table cellpadding="0" cellspacing="0" align="left">  <tbody><tr>   <td width="15" height="6"></td>  </tr>  <tr>   <td></td>   <td width="334" height="37" bgcolor="white" style="border-top-width: 0.75pt; border-right-width: 0.75pt; border-bottom-width: 0.75pt; border-left-width: 0.75pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: black; border-right-color: black; border-bottom-color: black; border-left-color: black; vertical-align: top; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="position:absolute;left:0pt;z-index:251660288">   <table cellpadding="0" cellspacing="0" width="100%">    <tbody><tr>     <td>     <div v:shape="_x0000_s1026" style="padding:4.35pt 7.95pt 4.35pt 7.95pt">     <p>&nbsp; &nbsp; scp&nbsp;     B<span style="font-family:宋体;">机器相应的目录</span>&nbsp; A<span style="font-family:宋体;">机器相应的目录</span></p>     </div>     </td>    </tr>   </tbody></table>   </span>&nbsp;</td>  </tr> </tbody></table>  &nbsp;</p>  <p>&nbsp;</p>  <br clear="ALL" />  <p>&nbsp;&nbsp; scp <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#113;&#105;&#110;&#108;&#101;&#105;&#48;&#49;&#64;&#100;&#98;&#45;&#103;&#111;&#117;&#121;&#105;&#46;&#100;&#98;&#48;&#49;&#58;&#47;&#104;&#111;&#109;&#101;&#47;&#117;&#115;&#101;&#114;&#115;&#47;&#113;&#105;&#110;&#108;&#101;&#105;&#48;&#49;&#47;&#120;&#120;&#120;">qinlei01@db-gouyi.db01:/home/users/qinlei01/xxx</a> /home/wiki/xxx</p>  <p>&nbsp;</p>  <p style="margin-left:36.0pt;text-indent:-36.0pt;"><strong><span style="font-size:16.0pt; font-family:宋体;">四、 </span></strong><strong><span style="font-size:16.0pt; font-family:宋体;">crontab</span></strong><strong><span style="font-size:16.0pt;font-family: 宋体;">添加任务</span></strong></p>  <p style="margin-left:18.0pt;text-indent:-18.0pt;"><span style="font-family:宋体;">1、<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; "> </span></span><span style=" font-family:宋体;">在A机器输入如下命令</span></p>  <p style="text-indent:10.5pt;"><span style="font-family:宋体;"># crontab &#8211;e </span><span style="font-family:宋体;">（打开crontab的任务列表文件）</span></p>  <p style="margin-left:18.0pt;text-indent:-18.0pt;"><span style="font-family:宋体;">2、<span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal; "> </span></span><span style=" font-family:宋体;">输入如上命令后，vi会打开一个文件（不用管他），在其中输入如下命令（如果你想每一分钟执行xx.sh的话）</span></p>  <p style="text-indent: 10.5pt; "><a><span style="font-family:宋体;color:#000088;background:lightgrey">*/1</span></a><span style="font-family:宋体;">&nbsp;</span><span style="font-family:宋体;color:#000088;background:lightgrey"> * * * * <a>/home/wiki/xx.sh</a></span></p>  <h1><span style="font-size:16.0pt;">五、附录</span></h1>  <p><span style="font-family:宋体;">1</span><span style="font-family:宋体;">、crontab使用：</span><a href="http://vbird.dic.ksu.edu.tw/linux_basic/0430cron.php#crontab">http://vbird.dic.ksu.edu.tw/linux_basic/0430cron.php#crontab</a></p>  <h1><span style="font-size:16.0pt;">六、完结</span></h1>    <p><span style="font-family:宋体;">到现在你的</span>xx.sh<span style="font-family:宋体;">脚本将会每隔一分钟执行拷贝任务了，这样你就不需要去关心从开发机拷贝代码到测试机的繁琐事务了。如果想即时将开发机上的代码拷贝到测试机上，只需手动执行</span>xx.sh<span style="font-family:宋体;">脚本即可。</span><br /> xx.sh<span style="font-family:宋体;">可以根据你的需要编写一些高级的逻辑，来判断文件自上次拷贝之后是否进行了修改，如果没有修改就跳过拷贝逻辑，来处理复杂的拷贝情况，这里给出</span> <span style="font-family:宋体;">一个实现方案：在开发机上建立一个文件</span>yy.txt,<span style="font-family:宋体;">并在开发机上运行一个脚本定时计算需要拷贝的文件的</span>md5<span style="font-family:宋体;">值，与之前保存在</span>yy.txt<span style="font-family:宋体;">中相应文件的</span> md5<span style="font-family:宋体;">值做比较，如果</span>md5<span style="font-family:宋体;">值改变，则写入另外一个文件</span>zz.txt,<span style="font-family:宋体;">然后测试机每隔固定时间从开发机拷贝这个</span>zz.txt<span style="font-family:宋体;">文件，这样测试机就知道哪些文</span> <span style="font-family:宋体;">件发生了改变，只需要拷贝</span>zz.txt<span style="font-family:宋体;">中的文件即可，注意</span>zz.txt<span style="font-family:宋体;">中的相应文件的</span>md5<span style="font-family:宋体;">值需要覆盖</span>yy.txt<span style="font-family:宋体;">中相应文件的</span>md5<span style="font-family:宋体;">值，便于下一次比</span> <span style="font-family:宋体;">较。当然如果觉得拷贝</span>zz.txt<span style="font-family:宋体;">也不够快速，可以考虑使用</span>k-v<span style="font-family:宋体;">数据库来存储。</span><br /> <span style="font-family:宋体;">希望这篇简单的文档能对你有所帮助。</span><br /> <br /> </p>  <div>  <hr align="left" size="1" width="33%" />    <div>  <div id="_com_1"></div></div><div><div id="_com_2">  </div>  </div></div><img src ="http://www.cppblog.com/aa19870406/aggbug/169053.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/aa19870406/" target="_blank">MrRightLeft</a> 2012-03-26 21:38 <a href="http://www.cppblog.com/aa19870406/archive/2012/03/26/169053.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解决mysql“Access denied for user 'root'@'localhost'”(转）</title><link>http://www.cppblog.com/aa19870406/archive/2011/05/29/147642.html</link><dc:creator>MrRightLeft</dc:creator><author>MrRightLeft</author><pubDate>Sun, 29 May 2011 13:00:00 GMT</pubDate><guid>http://www.cppblog.com/aa19870406/archive/2011/05/29/147642.html</guid><wfw:comment>http://www.cppblog.com/aa19870406/comments/147642.html</wfw:comment><comments>http://www.cppblog.com/aa19870406/archive/2011/05/29/147642.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/aa19870406/comments/commentRss/147642.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/aa19870406/services/trackbacks/147642.html</trackback:ping><description><![CDATA[<div><span style="border-collapse: collapse; font-family: song, Verdana; font-size: 12px; line-height: normal; ">转自：<a href="http://blogold.chinaunix.net/u1/35320/showart_305024.html">http://blogold.chinaunix.net/u1/35320/showart_305024.html</a><br />我的系统是ubuntu6.06，最近新装好的mysql在进入mysql工具时，总是有错误提示:<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -uroot -p<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password:<br style="font: normal normal normal 12px/normal song, Verdana; " />ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />使用网上介绍的方法修改root用户的密码：<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysqladmin -uroot -p password 'newpassword'<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password:<br style="font: normal normal normal 12px/normal song, Verdana; " />mysqladmin: connect to server at 'localhost' failed<br style="font: normal normal normal 12px/normal song, Verdana; " />error: 'Access denied for user 'root'@'localhost' (using password: YES)'<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />现在终于被我找到了解决方法，如下（请先测试方法三，谢谢！）：<br style="font: normal normal normal 12px/normal song, Verdana; " />方法一：<br style="font: normal normal normal 12px/normal song, Verdana; " /># /etc/init.d/mysql stop<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysqld_safe --user=mysql --skip-grant-tables --skip-networking &amp;<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -u root mysql<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; UPDATE user SET Password=PASSWORD('newpassword') where USER='root';<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; FLUSH PRIVILEGES;<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; quit<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " /># /etc/init.d/mysql restart<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -uroot -p<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password: &lt;输入新设的密码newpassword&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />方法二：<br style="font: normal normal normal 12px/normal song, Verdana; " />直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -udebian-sys-maint -p<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password: &lt;输入[client]节的密码&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; UPDATE user SET Password=PASSWORD('newpassword') where USER='root';<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; FLUSH PRIVILEGES;<br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt; quit<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -uroot -p<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password: &lt;输入新设的密码newpassword&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />mysql&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />方法三：<br style="font: normal normal normal 12px/normal song, Verdana; " />这种方法我没有进行过测试，因为我的root用户默认密码已经被我修改过了，那位有空测试一下，把结果告诉我，谢谢！！<br style="font: normal normal normal 12px/normal song, Verdana; " /># mysql -uroot -p<br style="font: normal normal normal 12px/normal song, Verdana; " />Enter password: &lt;输入/etc/mysql/debian.cnf文件中[client]节提供的密码&gt;<br style="font: normal normal normal 12px/normal song, Verdana; " /><br style="font: normal normal normal 12px/normal song, Verdana; " />至此，困惑多时的问题解决了！</span></div><img src ="http://www.cppblog.com/aa19870406/aggbug/147642.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/aa19870406/" target="_blank">MrRightLeft</a> 2011-05-29 21:00 <a href="http://www.cppblog.com/aa19870406/archive/2011/05/29/147642.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>5月29日学习笔记</title><link>http://www.cppblog.com/aa19870406/archive/2011/05/29/147630.html</link><dc:creator>MrRightLeft</dc:creator><author>MrRightLeft</author><pubDate>Sun, 29 May 2011 09:37:00 GMT</pubDate><guid>http://www.cppblog.com/aa19870406/archive/2011/05/29/147630.html</guid><wfw:comment>http://www.cppblog.com/aa19870406/comments/147630.html</wfw:comment><comments>http://www.cppblog.com/aa19870406/archive/2011/05/29/147630.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/aa19870406/comments/commentRss/147630.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/aa19870406/services/trackbacks/147630.html</trackback:ping><description><![CDATA[<div>1.linux查找命令<br />&nbsp; (1)find （2）locate (3)whereis (4)grep<br /><br />2.开源数据库（hash数据库-键值数据库）了解<br />&nbsp; （1）redis （2）tokyocabinet<br /><br />3.mysql安装配置<br /><br />4.linux shell及sed学习<br />&nbsp; （1）shell写的mp3自动下载代码学习 (2)sed及sedsed学习</div><img src ="http://www.cppblog.com/aa19870406/aggbug/147630.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/aa19870406/" target="_blank">MrRightLeft</a> 2011-05-29 17:37 <a href="http://www.cppblog.com/aa19870406/archive/2011/05/29/147630.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>