Transferring files
As you begin to do work on the Beowulf clusters maintained by VCU, you may eventually wish to copy some of your work from your local machine to your account on one of the clusters. Unfortunately, there may be an easy-to-overlook "gotcha" involved. This is a rare problem, but it does occur occasionally and cause frustration. There may be "hidden characters" in your file(s); they don't show up when you edit the file (usually) or otherwise view it, but they are there nonetheless. They are used for various formatting operations, such as tabbing, new lines, and so on.
In fact, newlines are usually the culprit in cases we've seen where files transferred from a Windows machine cause problems once put into use on a machine running Linux. This is because, under Windows, a newline is indicated in a text file with the hidden character '\r\n' (carriage return + line feed).
Depending on what you are doing on the Linux machine, this may never be a problem if your file is in this format. Certain software though is expecting input in Unix format, which means, newlines are expected to be indicated by the character '\n'. An example of having trouble with this is when someone works on an SGE job script on their Windows machine, and then copies it to say, the Teal cluster, and tries to submit the script to run a job. The qsub command used to submit the job will not recognize '\r\n', and the job will fail to run, with an error.
Here is the message seen from such a recent error:
This is pretty confusing the first time it's encountered! The second line, about the unexpected end of file, is caused by the real problem, the carriage return mentioned in the first line. In this case, the user was able to use a simple Linux utility, dos2unix, to convert the job script file to the proper format, and the job then was able to launch and run properly.
So, what is this "dos2unix"? It is a small program that will strip out things like the '\r' characters in files that are transferred from the Windows environment. Here is an example of using it on the Teal cluster; first, hidden characters will be displayed that are in a file, simple.sh:
Different programs will display something a little bit different to represent the presence of the carriage return, the cat command prints a '^M' (so will vim), and sed shows '\r'. Both show line-feed as '$'. The end of file (EOF) causes the prompt to not go to a newline at all. Let's clean things up using dos2unix:
In the first line, the dos2unix utility is used to reformat simple.sh, and save it as simple_converted.sh. If the -n flag isn't used, and a new filename provided for dos2unix to save the formatted changes as, the original file will be overwritten! This may not be what you wanted to happen, so please be aware of this behavior; you may wish to run "man dos2unix" at the command line to get more information.
Then the original file is displayed again, using the cat command, and the same is done to the new, Unix-formatted file. When the new file is displayed, it is missing the carriage-return (displayed as '^M' by the cat command).
As demonstrated, it's pretty easy using dos2unix to convert files brought over from Windows to a format that may be expected by the software you use under Linux. Hopefully this will help to eliminate an irritating and confusing "gotcha" problem. Of course, if other problems arise, feel free to contact folks in the HPRC (https://research.vcu.edu/cores/hprc/).