Scanning for CR/LF, want valid bash script

Quick Conversion Command

find . -name "*" -type f -exec dos2unix {} \;

Sample Script

#!/bin/sh
# MAKE SURE TO ALWAYS SAVE THIS FILE AS UNIX FORMAT.</code>

# Date: Monday, November 17, 2008 8:30 AM
# Author: Maurice Ruckman
#
# Description: Scan scripts directory looking for CR/LF which indicates
# a script was not saved in UNIX format. This would cause the script
# to fail.

grep -l -r $'\r\n' /devl/scripts > scan_for_crlf.output.txt

if [ -s scan_for_crlf.output.txt ]; then
echo "FAILURE CR/LF DETECTED IN SCRIPTS FOLDER"
echo "Found CR/LF when scanning scripts folder" | mailx -s "FAILURE FAILURE FAILURE CR/LF DETECTED IN SCRIPTS FOLDER" mruckman@hollandamerica.com
else
echo "ALL OKAY"
echo "All scripts passed test scan." | mailx -s "Scripts Folder Passed Scan" mruckman@hollandamerica.com
fi
find "/home/jboss1/workspace/HAL" -type f -name "*.java" > list.txt

We can easily convert the code with dos2unix

and find the problem code with something like this:

grep -l -r $'\r\n' /home/jboss1/workspace/HAL

or just convert everything by scripting it, here's a start

find "/home/jboss1/workspace/HAL" -type f -name "*.java"

Leave a Reply