LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Script bombs on embedded Linux system (Altiris) (https://www.linuxquestions.org/questions/programming-9/bash-script-bombs-on-embedded-linux-system-altiris-700799/)

GNUJoshua 01-29-2009 08:30 AM

Bash Script bombs on embedded Linux system (Altiris)
 
I use a linux pre-installation environment to image workstations with Windows XP. This deployment product is Symantec's Altiris Deployment Solution. We are trying to build an automated installer that asks the tech questions, which will be inserted into the sysprep of the Windows system. We are trying to build DVD disks that will image for places without direct access to an altiris server.

And have a working way to drop down my image, which is good. What's bad is how built-in scripts are handled vs. typed commands...

To "make sure" these scripts would work, I created them after booting to the Linux environment from a Linux Managed altiris environment. Ran the scripts and they worked, just fine... so I committed them to the boot disk.

I get odd errors when trying to run the exact same scripts that I verified working by typing them in manually.

Here's an example of code from my script that is completely bombing out. This information is important because we manually modify our sysprep file when imaging (we have 5 domains and potential domain admins for joining):
Code:

#!/bin/bash
read -p "Enter DOMAIN to join " SNDOMAIN
read -p "Enter ADMIN USERID " SNUSER
read -p "Enter ADMIN PASSWORD " SNPASS
mkdir /dstemp
cat /mnt/atrsboot/sysprep.inf > /dstemp/xpprep.live
sed -e "s/SNDOMAIN/$SNDOMAIN/g" -i /dstemp/xpprep.live
sed -e "s/SNUSER/$SNUSER/g" -i /dstemp/xpprep.live
sed -e "s/SNPASS/$SNPASS/g" -i /dstemp/xpprep.live
/mnt/atrsboot/firm copy "/dstemp/xpprep.live" "prod:/Sysprep/sysprep.inf"

When testing this, as typed, the script would take the variables SNDOMAIN, SNUSER, and SNPASS and use sed to replace variables in the sysprep file, then it would insert the sysprep into the newly imaged system. I know this is a long post so I'll reiterate... the script worked FINE when typing the commands in manually.

Problem is, I'm getting errors that would hint towards a command interpreter or keyboard error... errors such as: (I've bolded manual input)
Code:

Enter DOMAIN to join mydomain.com
': not a valid identifier line 2: read: 'SNDOMAIN
Enter ADMIN USERID gnujoshua
': not a valid identifier line 3: read: 'SNUSER

Any clues are more than welcome... I've tried placing quotes around the variables "just in case", exact same result. I've also used the following:
Code:

echo "Please enter DOMAIN "
read SNDOMAIN

With the same result...

colucix 01-29-2009 08:55 AM

What is not really clear to me is: have you edited these files under windows or under linux? If you have edited the scripts under windows, most likely the line terminator is a carriage return which is not correctly managed by shell scripts in linux. I mean you have to convert them in Unix format prior to feed the shell with these script.

In Linux you can do this using the dos2unix command. Or eventually rewrite the scripts in a Linux environment using vi or any other available editor. I bet the problem magically disappear.

GNUJoshua 01-29-2009 09:41 AM

Quote:

Originally Posted by colucix (Post 3425248)
What is not really clear to me is: have you edited these files under windows or under linux? If you have edited the scripts under windows, most likely the line terminator is a carriage return which is not correctly managed by shell scripts in linux. I mean you have to convert them in Unix format prior to feed the shell with these script.

In Linux you can do this using the dos2unix command. Or eventually rewrite the scripts in a Linux environment using vi or any other available editor. I bet the problem magically disappear.

I thought of that and am toasting a CD now to test. After opening the script up for editing in the Linux environment (using vi) I noticed the ^M after every line... I missed the CR's prior due to using cat to review the script.

GNUJoshua 01-29-2009 12:15 PM

THat was it, thanks colucix!


All times are GMT -5. The time now is 12:29 PM.