Welcome Anonymousregister
Categories
· Home
· Authors and Articles
· Downloads
· Feedback
· Forums
· Journal
· Private Messages
· Recommend Us
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Web Links
· Your Account

Survey
What Topics Of FreeBSD Servers & Workstations Do You Want More Information About?

FreeBSD Installation
Webserver Setup
E-Mail Server Setup
IRC Server Setup
Mailing Lists
Autoresponders
Scripting
Software Coding
Server Security
Installing Ports
Domain Servers
Website Design



Results
Polls

Votes: 23
Comments: 0

 Title : Scripting: How To Batch Remove ^M From PC Files
Scripting
Scripting


Removing ^M From Files Saved Within Windows Is Easy Using This Utility.

This is probably one of the most annoying issues you have to deal with when you open a lot of files which have either been on a windows system or were created on a windows machine, and that is removing those pesky ^M symbols when viewed on a Unix box.  Generally these carriage return symbols (^M) don't do any harm when they are within Unix files but they are annoying and make the file your viewing that much harder to read. 

If you are anything like I am when it comes to these, you want an easy way to remove them from a batch of files all at once and not waste a whole lot of time on them.  The utility I use to remove them is called dos2unix and it can be found in the ports tree at
/usr/ports/converters/unix2dos Now you're probably asking, 'Wait, I thought you said it was dos2unix', yes you're right I did, but included in the unix2dos application is the dos2unix command which we will be using.

<------Begin Type Within a Shell------->
#cd /usr/ports/converters/unix2dos
#make clean
===>  Cleaning for unix2dos-1.3
#make install distclean
######Code Compiles#######
#rehash
<-------End Type Within a Shell-------->


Once you have compiled unix2dos you will issue the following command from the shell:

<-------Begin Type Within a Shell------->
#
find /path/to/folder/of/files/to/process/ -name "*.php" -print -type f -exec dos2unix {} \;
<-------End Type Within a Shell--------->

This will spit out a list of the files that it found within this folder and execute the dos2unix command on the files with the extension of .php.

Now there are probably a million different ways to accomplish the task of removing these carriage return within your files, but I found that using this method to do a batch search and execute is the simplest most effective way of doing this chore.

You can use other tools to remove these ^M symbols from your files and if you're are just dealing with one file then this may be a little overboard.  You could use perl to do this for example by doing the following:


<-------Begin Type Within a Shell------>
#perl -pi -e 's/
\015//g' filename
<-------End Type Within a Shell-------->

I hope you find this as useful as I do when dealing with files that you move from a windows  box to your FreeBSD machine.  These are the kinds of hacks that make using FreeBSD so much fun.



Sunday, December 02, 2007 @ 17:38:07 EST
(comments? | Score: 5)

 Title : Scripting: Using Date Function To Automate Saving Of Mysql Database Files
Scripting
Scripting


We Show You How To Use The Date Function To Save Reoccurring Files Which Would Otherwise Get Overwritten

One of the first things I ran into when beginning my FreeBSD adventure was finding a way to automatically backup my web servers mysql database files. I found that even webmin (an application management interface) wasn't able to handle saving of my mysql database files without overwriting the previously saved (day before) files.

As you may already know it's especially important with websites that you have progressive saves of the database in case you find a problem that requires you use a version of your site that happened 7 days previously.  If you are new to scripting then all of this may not be something you will understand right off the bat, but eventually you'll understand the power of using the date function within your scripts when saving files.  Essentially what this date function does is add a time stamp to the end of your file name so that it is completely unique because it's based off the current time of when the file is being saved. 

What I did in my case was create a small script called websiteback.sh that I then placed in a bin directory within my home such as /root/bin/websiteback.sh.  For this example I simplified the code within this file just for the sake of simplicity for those new to scripting.  Basically what this file contains a line for each database within my system as follows:

<-----Begin File Code----->
#!/bin/sh
/usr/local/bin/mysqldump -u root --password=aBcD1234 dataBaseName > /location/you/want/to/save/backup/dataBaseName.`date +%m%d%Y%H%M%S`

/usr/local/bin/mysqldump -u root --password=aBcD1234 dataBaseName2 > /location/you/want/to/save/backup/dataBaseName2.`date +%m%d%Y%H%M%S`
<-----End File Code------>

The first line executes this file as a shell script via sh which needs to be set as an executable otherwise it will not run.  See man chmod if you aren't sure how to set it executable. 

Once you have created this file, the only thing left to do is create a cron job to execute the above file on a daily basis.  For example you would create a cron job like the following:

0 8 * * * /root/bin/websiteback.sh

See man crontab for more information about how to set a cron job within FreeBSD.  That's all there is to it! 

Using the date function is very versatile and you can use it directly within your scripts and can use them within paths as I've shown above.  I hope you find it as useful as I do and if you have any questions or comments, please feel free to post them here. 



Friday, November 30, 2007 @ 22:16:20 EST
(comments? | Score: 5)

Hacks Members
Your IP: 38.107.191.104

Welcome, Anonymous
Nickname
Password
Security Code
Security Code
Type Security Code


· Register
· Lost Password
Server Date/Time
4 September 2010 19:00:30 EDT (GMT -4)

Related Links


Random Headlines

Sendmail
[ Sendmail ]


Big Story of Today
There isn't a Biggest Story for Today, yet.

Old Articles
There isn't content right now for this block.

Information

Powered by RavenNuke(tm)


1: Credit Repair Combat
128 times
2: My Internet Business
123 times
0.175 Seconds