Nuka Raku
Nuka Raku

Reputation: 95

Linux Shell commands work when manually typed. Don't work when put in a script file

I have this Linux script called LinuxCommands used to check to make sure that my machine has the pre-requisites that Oracle requires for an install. The script will work if I copy all of the text from a Windows notepad and paste it into my Linux terminal, but don't work when I ftp over the actual .sh file to the Linux terminal and run it by calling bash. The script does not work at all if I use ./ notation. I am using root for both copying the commands and running the file using ./ or bash notation. The Linux script is as follows

#!/bin/bash
#Install packages, upgrade those that already exist

PKG_OK=$(dpkg-query -W --showformat='${Status}\n' binutils-2.17.50.0.6 compat-libstdc++-33-3.2.3 compat-libstdc++-33-3.2.3 elfutils-libelf-0.125 elfutils-libelf-devel-0.125 gcc-4.1.2 gcc-c++-4.1.2 glibc-2.5-24 glibc-common-2.5 glibc-devel-2.5 glibc-headers-2.5 ksh-20060214 libaio-0.3.106 libaio-devel-0.3.106 libgcc-4.1.2 libstdc++-4.1.2 libstdc++-devel make-3.81 sysstat-7.0.2|grep "install ok installed")
echo Checking for libraries: $PKG_OK
if [ "" == "$PKG_OK" ]; then
  echo "Not Installed. Installing"
  yum -y install binutils-2.17.50.0.6 compat-libstdc++-33-3.2.3 compat-libstdc++-33-3.2.3 elfutils-libelf-0.125 elfutils-libelf-devel-0.125 gcc-4.1.2 gcc-c++-4.1.2 glibc-2.5-24 glibc-common-2.5 glibc-devel-2.5 glibc-headers-2.5 ksh-20060214 libaio-0.3.106 libaio-devel-0.3.106 libgcc-4.1.2 libstdc++-4.1.2 libstdc++-devel make-3.81 sysstat-7.0.2
fi


#Adds oinstall and dba groups
/bin/id -g oinstall 2>/dev/null \
[ $? -eq 0 ] && echo "Group found" || sudo /usr/sbin/groupadd oinstall

/bin/id -g dba 2>/dev/null \
[ $? -eq 0 ] && echo "Group found" || sudo /usr/sbin/groupadd dba

#Adds oracle user in oinstall group

if id -u oracle >/dev/null 2>&1; then
        echo "user exists"
else
        /usr/sbin/useradd -m -g oinstall -G dba oracle
fi

#Creates installation directory for Oracle
chown -R oracle:oinstall /u00/Oracle12CInstall
chmod -R 775 /u00/Oracle12CInstall

#Adds Oracle variables to the Oracle User's profile.
cat <<EOF > /home/oracle/.bash_profile
ORACLE_BASE=/u00/Oracle12cInstall
ORACLE_HOME=$ORACLE_BASE/test2/product/121
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_BASE
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:/usr/X11R6/bin:/usr/lib

export PATH

export ORACLE_BASE ORACLE_HOME LD_LIBRARY_PATH
umask 022

EOF

The error I get when I run it on a Linux terminal is

bash LinuxCommands
: command not found 3:
LinuxCommands: line 4: dpkg-query: command not found
Checking for libraries:
LinuxCommands: line 47: syntax error: unexpected end of file

Upvotes: 0

Views: 394

Answers (1)

Nuka Raku
Nuka Raku

Reputation: 95

This question was solved by running

dos2unix LinuxCommands

Command above removed DOS line endings from my file snd it was able to run sucessfully.

Upvotes: 1

Related Questions