.sh Script not running on AWS EC2

Siraj Syed asked:

I downloaded a .sh file from S3 Bucket using the command

 /usr/local/bin/aws s3 cp s3://mm-s3-encrypt/AppD.sh /prod/msp/domains/dynamicapp_domains/

I do see it in the path,
I do a

chmod u+x AppD.sh

then ,

./AppD.sh

Result of this

: [No such file or directory]omains/dynamicapp_domains/
: [No such file or directory]omains/dynamicapp_domains/msp_dynamicapp_tomcat_01/bin
cp: cannot stat `startup.sh': No such file or directory
: No such file or directory
: No such file or directory
: No such file or directory
: No such file or directory
: No such file or directory
--2015-10-28 11:32:24--  https://nexus.kdc.capitalone.com/mother/service/local/repositories/WildWildWest/content/com/AppD_AppAgent/4.1.4.3/AppD_AppAgent-4.1.4.3-AppAgent.zip%0D
Resolving nexus.kdc.capitalone.com... 10.42.17.183
Connecting to nexus.kdc.capitalone.com|10.42.17.183|:443... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authorization failed.

but separately these commands are working fine , here is the script

 #!/bin/bash
 cd /prod/msp/domains/dynamicapp_domains/.
 mkdir -p  /AppDynamic/AppAgent
 mkdir -p /AppDynamic/MachineAgent 
 cd /prod/msp/domains/dynamicapp_domains/msp_dynamicapp_tomcat_01/bin/. 
cp startup.sh startup.sh_orig 
HOST=$(hostname)
 sed -i '7iexport
> CATALINA_OPTS="$CATALINA_OPTS-javaagent:/prod/msp/domains/dynamicapp_domains/AppDynamic/AppAgent/ver4.1.4.3/javaagent.jar"'
> startup.sh sed -i '10iENABLE_AppD_PROBE="YES";' startup.sh 
sed -i.bak -e '15,16d' startup.sh 
sed -i '15iif [ ! -z ${ENABLE_AppD_PROBE} ]; then' startup.sh
sed -i '16iPROBE_OPTS="-javaagent:/prod/msp/domains/dynamicapp_domains/AppDynamic/AppAgent/ver4.1.4.3/javaagent.jar -Dprobe.id='"$HOST"'_msp_dynamicapp_tomcat_01 -Dprobe.group='"$HOST"'";' startup.sh 
cd /prod/msp/domains/dynamicapp_domains/AppDynamic/AppAgent/. 
wget https://nexus.kdc.capitalone.com/mother/service/local/repositories/WildWildWest/content/com/AppD_AppAgent/4.1.4.3/AppD_AppAgent-4.1.4.3-AppAgent.zip

My answer:


You edited your shell script with a Windows text editor (never, ever do this if you value your sanity) and as a result it has carriage returns at the end of every line. These are not treated specially by UNIX-like operating systems.

To fix the file, run dos2unix on it.

dos2unix AppD.sh

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.