Linux “: command not found” Error – Windows Line Break

Today, I am working on a project, that uses Puppet template to create a stackdriver config file: /etc/sysconfig/stackdriver

For some reason, this Puppet template (.erb) is ‘dos’ file format (from my colleague), which is Windows format. The line break is CR + LF. Usually this is OK, because the config file mostly just for Linux service to read. However, in stackdriver service startup script, there is a line ‘ . /etc/sysconfig/stackdriver ‘. Stackdrive service uses this config file to initial certain variables. In this case, if you have Windows line breaks in the config file, you will see this error:

: command not found
: command not found

I then use sublime text to recreate this file in unix file format, problem goes away. Hope this helps someone.

These sublime text personal preference setting are recommended, unless you are a Windows platform developer:

{
"default_line_ending": "unix",
"translate_tabs_to_spaces": true
}

Update: It turns out it is because I copied the files from my Windows PC over to Linux server. What I should do is to git clone the files on the Linux server. This way Git will help deal with the line ending issue.

Bash – set variable with or without export are different

I am working on an AWS ec2 instance provisioning script today. I am using Packer to provision the instance and build an AMI. The instance is running Ubuntu. There is a very annoying error when I am using ‘apt-get -y upgrade’ or ‘apt-get -y install’:

debconf: unable to initialize frontend: Dialog
debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

Google it and not hard to find the fix is to add “DEBIAN_FRONTEND=noninteractive” in your script
(credit to link to stackoverflow)

However, it still doesn’t work for me until I realize I need to put in ‘export’:

export DEBIAN_FRONTEND=noninteractive

Apparently ‘export’ will make the variable is available to any process you run from your current shell process (not parent process though). Without ‘export’, the variable scope is restricted to the shell, and is not available to any other process.
(credit to link to stackoverflow)

“File path too long” error when copying files in Windows SBS

It was painful when you need to copy large amount of data from one server to the other and came across this “file path too long” error. That means you will need to dig into each subfolder to either rename the file or zip them up. That would take all night if you have a lot of this errors. I had this problem today.

What I am doing is helping a client migrate Windows SBS 2008 to Windows SBS 2011. There are over 200G data to copy across. For the first couple of “file path too long” errors, I just mark them down until I find there are too many of them.

Quick search on Google leads me to RoboCopy . I have to say this is an excellent tool to handle exactly this case. Actually people are using this tool to do server backup too.

robocopy "\\server1\folder1" "D:\folder2" /e /z /dcopy:T /XO

A simple command line came to rescue. I can then sit back and enjoy my coffee.

Update: Just realise today that you can use robocopy to delete files as well:
create a empty folder and run this command:

robocopy e:\empty e:\to_delete /MIR /E