Archive for the ‘Scripts’ Category
Feb
22
Here we go folks, I thought I would share a handy little script with you that I use to backup all of the databases on a particular Linux/UNIX server. I do this by getting a list of the databases, and then using mysqldump to dump them all to a text file. This seems to be the best way (short of replication) to get good clean backups of the data. Toss it into a cron job and you can have it done automagically. There isn’t anything yet to rotate files, but I might add that later. Also, I am going to try and rewrite this in PERL so our Windows (and other OS’s that don’t have a shell like Bash) brethren can run this script as well. For now though, it’s written for Bash but almost any shell would work I think.
OK, onto the script. Read the rest of this entry »
Sep
20
Recently I was working on a script for log reporting. You know, one of those handy little guys that send you some info every day helping to make sure you keep up with whatever it is that you don’t want to forget about. Well, some of the data was in a plain old text file, and there is nothing wrong with that. It’s easy to simply cat the file and pipe it through mailx or mutt, no fuss, no muss.
Read the rest of this entry »
Mar
16
Hey all your PERL junkies like me, I have a present for you. Anyone that has done any coding at all other PERL will know (and miss) the round function that most other languages have built in. For those that may not know, the round function lets you do just that, round a number to the specified digit. So, instead of having to use 3.14159265 as an answer for a particular equation, you could round it to 3.14. Nice, huh?
Well, here is a neato little round function that you can drop into your PERL scripts and call to actually round numbers instead of cutting them off with ceil or cut. Check it out:
sub round {
my($number) = shift;
return int($number + .5 * ($number <=> 0));
}
There you go!
**Update**
Thanks to Thierry H. for adding a little mod to the round function allowing you to specify the number of decimals to print. Here is the modified function:
sub round {
my $number = shift || 0;
my $dec = 10 ** (shift || 0);
return int( $dec * $number + .5 * ($number <=> 0)) / $dec;
}
You would call it by giving not only the number to round, but how many numbers to show on the right side of the decimal. It will look like so:
$result = round(123.4567,3);
This should return 123.457 (the 6 in the third slot gets rounded to 7). There ya go, thanks for the mod Thierry! You can check out Thierry’s site here.
Jan
19
Have you ever wanted to add an option to that ornery right click context menu so you could open whatever file you just clicked on with whatever the heck you please? I know I have, and here is a quick tip to do just that! Whether it’s your favorite text editor, or another app that you want for some reason, you can easily add an Open With option to the context menu by modifying and then importing this registry file.
Read the rest of this entry »
Dec
23
Sometimes we have to generate passwords in our code, no problem. But what about when you need to generate a password that is compatible with the htpasswd command, as in the password is the same as what would be generated by htpasswd? Well, if you are using PHP, you can use this function that I posted in the forums. Check it out …
Oct
21
Ok, here is a quick tip that has come in handy quite a few times in my days writing shell scripts, for example in bash. Let’s say, for whatever reason, you need to chop off the end of a string (like a variable). Chopping the beginning is easy, just use the cut command, but in order to chop the end you have to know how long the string is so you can tell it where to start. In this example, we are going to us the wc command to figure out how long the string is, and then subtract 1 to cut the last character. You can subtract however many you want depending on how many characters you want to cut. Check it out … Read the rest of this entry »