Working between Windows and Linux machines can be liberating, but a bit of a pain at times. One of these times is when creating scripts on a Windows PC and copying them over to a Linux box only to receive “$’\r’: command not found” when attempting to execute them.
This is due to the files being saved in DOS format where new lines are delimited with \r\n as opposed to the *nix \n format.
You can either ensure the files are saved in Unix format in your Win text editor, or even use this extremely easy method to process them on the Linux box:
sudo apt-get install dos2unix
sudo dos2unix <your filename here>
I tend to create a lot of proofs of concept, be it applications or servers, and this process will usually start with spinning up a VM. For this I prefer to use Oracle’s VirtualBox mainly because it’s free and easy to use.
However, using VirtualBox each time I want to start and stop the VM isn’t great as it will open up the VM in a new window and you need to have both the VM window and VirtualBox running on your machine at the same time.
Luckily you can use the “start” command to run VirtualBox’s VBoxHeadless application to boot up a VM without starting VirtualBox itself and without having a window open, other than the command line.
start "Build Server VM" /D"C:\Program Files\Oracle\VirtualBox\" /MIN VBoxHeadless.exe --startvm "Server 2008 32"
Just make sure the name of the VM at the end of the command is the same as that within VirtualBox:
You can then access this via RDP (if your VM is windows) or SSH (if it’s Linux), as can anyone else on your network, should you have configured its network settings correctly.
Really simple stuff which is helping me out when hosting multiple sites for development on one machine; you either pass in as parameters or specify as responses
- the directory name of your site – e.g. “D:\Dev\MySite1” would be “MySite1”
- the port number you want it on
- the site ID
and it’ll set up the site, migrate your config settings to II7 if necessary, start the new site and let you know the URL to access it.
if [%1]== set /P directory="Enter name of directory/site: "
if [%2]== set /P port="Enter port number: "
if [%3]== set /P sitenum="Enter site number: "
%systemroot%\system32\inetsrv\appcmd add site /name:"%directory%" /id:%sitenum% /physicalPath:"D:\Dev\%directory%" /bindings:http/*:%port%:%computername%
%SystemRoot%\system32\inetsrv\appcmd migrate config "%directory%/"
%SystemRoot%\system32\inetsrv\appcmd start site "%directory%"
echo site "%directory%" now running at http://%computername%:%port%
if [%1]== (if [%2]== (if [%3]== (
I will change this to pull the next available site ID and port number unless someone else can tell me how to do that.
And yes, this would be very easy in Powershell but I’ve not done that version either..!
Also, if you’d like to know how I managed to get Syntaxhighlighter to work nicely with batch/cmd/dos, leave a comment. There are *no* nice, simple, tutorials out there with common mistakes, so I could paste my steps in here if necessary.