-
How to use a Windows .bat file to delete files on a schedule
This is how you delete files of a certain age using a scheduled task to execute a .bat file. These instructions mainly apply to Windows Server 2012 R2, but they are applicable to most newer (and older) versions of Windows. This is similar to the post I made many years ago but with some additions mainly around the commands you need to find files that are older than a certain date and then deleting them. It also focuses on Server 2012 R2 versus the older 2008.
The first thing we want to do is create the batch file that we will use to delete the files older than X days. To do this we will need to use the forfiles command in Windows. This is a very handy command for batch files IMO. Here is a run down of the forfiles command and how to use it:
Read the rest of this entry » -
Shell script to get all WordPress databases and URL’s
Below you will find a simple script that you can use to find all the databases and URL’s associated to wordpress sites in a shared database. This script requires a SQL user with the ability to ‘show databases’ and access to the DB’s you want to query.
The script grabs a list of all the databases on the server then loops through them all retrieving the URL from the wp_options table. The script also takes into consideration the fact the the table might not actually be wp_options (could contain some random characters) so we use a wildcard there.
-
Useful commands to run in a terminal
With the 1000’s of commands used over the years I sometimes forget what I have run. This post is a collection of commands that have been useful for me in the past and might be useful to others too. All commands are set to run from local(.).
CREATE AN SSH TUNNEL (remember -i if using pem):
ssh -C2qTnN -D 8080 user@location
FIND ALL FILES/DIRECTORIES WITH XXX PERMS AND CHANGE IT TO XXX:
Files:find . -type d -perm 0XXX -exec sudo chmod XXX {} \;
Directories:
find . -type f -perm 0XXX -exec sudo chmod XXX {} \;
-
Merging 100+K Gzipped Files Together
In order to open a large volume of cloudfront logs in a spreadsheet, we needed to merge over 100K .gz files on OS X Maverick into a single file. Trying to use the following command resulted in a /usr/bin/cat: Argument list too long error:
cat logs/*.gz >> combined_logs.gz
The reason this error occurs is because bash expands the asterisk to all matching files, producing a very long command line. To circumvent this problem the xargs command needs to be used to split up the list:
Read the rest of this entry » -
How to change the default SSH port in OSX Server
So you don’t want to have your remote login port (ssh port) on your OSX server setup to port 22. You can easily change the listening port doing the following 2 steps. There is no need to add another service.
First you will need to edit your Lion Services file:sudo nano /etc/services