LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-13-2011, 03:24 PM   #1
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Rep: Reputation: Disabled
Bash script execution error


Hello everybody,
My situation is a little difficult but i will try to explain what is the exact problem that i am facing.I have a bash script that I want to execute.
The script is described below and I am executing it on a Solaris X.




When I execute it I get the following


# sh ALU_SOL_SET_HOST_SCRIPT.sh
ALU_SOL_SET_HOST_SCRIPT.sh: ^M: not found

ALU_SOL_SET_HOST_SCRIPT.sh: ^M: not found
cd /var/tmp/
ALU_SOL_SET_HOST_SCRIPT.sh: /var/tmp/^M: does not exist


When I open the script with vi I can see the ^M argument @ every line.I am not sure whether the ^M argument is the problem here.I guess I will remove it and check but I would like your professional opinion on the matter.Is the ^M symbol supposed to show up in vi on every line?
If i do just a regular cat ALU_SOL_SET_HOST_SCRIPT.sh it doesnt show any ^M symbols.


# cat ALU_SOL_SET_HOST_SCRIPT.sh
#!/bin/sh
###########################################################
############################################################

set -x

cd /var/tmp/

echo "######################################################" > /var/tmp/configure_hostname.log
echo "CENSORED STUFF" >> /var/tmp/configure_hostname.log
echo "######################################################" >> /var/tmp/configure_hostname.log

DOMAIN=`/CENSORED STUFF "ALL_SYSTEM_DOMAIN"`
if [ "$?" != 0 ]; then
echo "Couldn't find ALL_SYSTEM_DOMAIN custom attribute" >> /var/tmp/configure_hostname.log
exit 1
fi
if [ ${DOMAIN} = 1 ]; then
echo "ALL_SYSTEM_DOMAIN custom attribute is not set properly" >> /var/tmp/configure_hostname.log
exit 1
fi

HOSTNAME=`/CENSORED STUFF "ALL_SYSTEM_HOSTNAME"`
if [ "$?" != 0 ]; then
echo "Couldn't find ALL_SYSTEM_HOSTNAME custom attribute" >> /var/tmp/configure_hostname.log
exit 1
fi
if [ ${HOSTNAME} = 1 ]; then
echo "ALL_SYSTEM_HOSTNAME custom attribute is not set properly" >> /var/tmp/configure_hostname.log
exit 1
fi

IP=`CENSORED STUFF "ALL_NETWORK_PRD_IP"`
if [ "$?" != 0 ]; then
echo "Couldn't find ALL_NETWORK_PRD_IP custom attribute" >> /var/tmp/configure_hostname.log
exit 1
fi
if [ ${IP} = 1 ]; then
echo "ALL_NETWORK_PRD_IP custom attribute is not set properly" >> /var/tmp/configure_hostname.log
exit 1
fi

#1. Configure /etc/hosts
echo "/etc/hosts:" >> /var/tmp/configure_hostname.log
cp /etc/hosts /var/tmp/hosts.sav
echo "#" > /etc/hosts
echo "# Internet host table" >> /etc/hosts
echo "#" >> /etc/hosts
echo "::1 localhost" >> /etc/hosts
echo "127.0.0.1 localhost" >> /etc/hosts
echo "${IP} ${HOSTNAME} ${HOSTNAME}.${DOMAIN}" >> /etc/hosts
cat /etc/hosts >> /var/tmp/configure_hostname.log
echo "######################################################" >> /var/tmp/configure_hostname.log

#2. configure hostname
echo "hostame:" >> /var/tmp/configure_hostname.log
echo "${HOSTNAME}" > /etc/nodename
hostname ${HOSTNAME}
echo `hostname` >> /var/tmp/configure_hostname.log
echo "######################################################" >> /var/tmp/configure_hostname.log

#3. configure other files
cp /etc/hosts /etc/inet/hosts

# restart network service
svcadm restart network/physical >> /var/tmp/configure_hostname.log

echo "######################################################" >> /var/tmp/configure_hostname.log
# force to update SA DB with latest info
/CENSORED STUFF/pylibs/cog/bs_hardware >> /var/tmp/configure_hostname.log
/CENSORED STUFFpylibs/cog/bs_software >> /var/tmp/configure_hostname.log


echo "######################################################" >> /var/tmp/configure_hostname.log
echo "END PROCESS" >> /var/tmp/configure_hostname.log
echo "######################################################" >> /var/tmp/configure_hostname.log

Last edited by dann_radkov; 09-13-2011 at 03:27 PM. Reason: typo
 
Old 09-13-2011, 03:33 PM   #2
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Did you create this file in Windows and then ftp/scp it to a Linux box in binary mode? Because vi displays the Windows CR+LF character as ^M.

Delete that from every line, you should be good to go. There are utilities that can fix it for you, too. Check out dos2unix for one.
 
Old 09-13-2011, 03:39 PM   #3
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Original Poster
Rep: Reputation: Disabled
Great I am doing it @ the moment.Actually someone else did the transfer.I suspected that but I wanted to present all info.Thanks for the quick response.Wow this forum is amazing 2-3 mins to respond.Thanks for that SL00b !!
 
Old 09-13-2011, 03:41 PM   #4
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Let the other person know that if he sends the file next time in ASCII mode, this problem would be avoided.

Glad to help.
 
Old 09-13-2011, 04:15 PM   #5
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Original Poster
Rep: Reputation: Disabled
I executed the script and it works as expected.Now I will convert those files (which were deployed as ZIP`s originally) into ASCII and will try it again.Thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect bash script source vs. direct execution Jessard Programming 11 11-30-2010 07:43 AM
Execution of awk script gives error message for invalid character tanggo81 Linux - Kernel 2 06-26-2010 03:35 AM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 08:05 PM
BASH: open console on script execution Quis Programming 2 02-07-2006 10:41 AM
script execution error linux_lover2005 Programming 3 12-22-2004 07:46 AM


All times are GMT -5. The time now is 04:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration