Shell Scripting Error - help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting Error - help
# 1  
Old 09-22-2012
Shell Scripting Error - help

I am trying to do an upgrade on a VMWare appliance. I am getting an error, and I dug into the script that is causing the error and will post the statement that is causing the error. Basically, my software seems to want an additional partition before it will do the upgrade. So, I added a new partition to the VM and left it in every possible state - formatted, not formatted, mounted, not mounted.. etc. I am going to post the script, if you can help me understand what the fdisk -l (list fdisk) output is causing this to error - I would appreciate it. I will also post the section that is next which is what would happen if it succeeded. Thank you in advance for your help.
Code:
function vmware_check_additional_disk()
{
if [ "$MODEL" == "VMWARE" ]; then
LogMessage "INFO" "VMWARE - verify additional disk is available..."
TMPFILE1=`mktemp -t ap.tmp.XXXXXXXX` || exit 1
TMPFILE2=`mktemp -t ap.tmp.XXXXXXXX` || exit 1
# Require additional disk added to the VM first if not abort.
RESET_HDD=$(fdisk -l 2>&1 | grep "contain a valid partition table" | awk '{print $2}' | tail -n1)
if [ -z $RESET_HDD ]; then
rm -f /tmp/ap.tmp.*
LogMessage "ERROR" "VMWARE - Unable to locate new empty partition added to the VM..."
return 1
fi
RESET_PARTITION="${RESET_HDD}1"
echo "p\n" > $TMPFILE1
echo "q\n" >> $TMPFILE1
fdisk $RESET_HDD < $TMPFILE1 > $TMPFILE2 2>&1
HDD_SIZE_TMP=$(egrep '^Disk' $TMPFILE2 | awk '{print $5}')
is_integer $HDD_SIZE_TMP
if [ $? -ne 0 ]; then
rm -f /tmp/ap.tmp.*
LogMessage "ERROR" "VMWARE - Unable to determine disk size $HDD_SIZE bytes..."
return 1
fi
# convert bytes to MG
HDD_SIZE=$(($HDD_SIZE_TMP>>20))
if [ $HDD_SIZE -lt 2000 ]; then
rm -f /tmp/ap.tmp.*
LogMessage "ERROR" "VMWARE - Can't setup reset image in partition smaller than 2000 MB"
return 1
fi
rm -f /tmp/ap.tmp.*
fi

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 09-22-2012 at 06:12 PM..
# 2  
Old 09-23-2012
Odd construct that. How about a here doc?

Code:
fdisk $RESET_HDD <<EOF  > $TMPFILE2 2>&1
p
q
EOF

I don't think there should be an extra newline there. which the shell script could insert. I may be wrong. Can you run fdisk with the value of $RESET_HDD manually, emulating what the code is trying to do: enter a p and enter a q

If you can decide what $TMPFILE2 and $TMPFILE1 translate to, try
Code:
cat $TMPFILE1
cat $TMPFILE2

This will tell you if you got a straight p and q. Some versions of echo do NOT by default decode \n into a newline. You may be getting garbage like "pn". fdisk will produce an error as well that you can see.

What the script code is doing is running the fdisk program "interactively" with canned responses. A more reasonable approach is a here doc, as above.

Do you have nonstandard aliases or symlinks for the shells - /bin/bash especially? what does the output of
Code:
type echo

give? It should be "echo is a shell builtin". The "real" bash echo will ignore those \n characters. Otherwise you may get garbage in $TMPFILE1

Code:
type echo
echo is a shell builtin
echo "p\n"> file
echo "q\n" >> file
cat file

gives
Code:
p
q

NO extra newline characters or garbage extraneous characters.

Last edited by jim mcnamara; 09-23-2012 at 12:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting syntax error in if then else

I have one bash shell script to execute table refreshment. At the bottom of script, I have one piece of code to check 'ORA-' error from log file, then send email to DBA or application people. But this piece of code didn't work. I tried different ways and also search online to find where is my... (2 Replies)
Discussion started by: duke0001
2 Replies

2. Shell Programming and Scripting

Error in tsch shell scripting..

Hi Everyone, I am using gdb-7.5 to connect to the target. When I gave the./configure --target=xyz --build=i686-pc-mingw32 --host=i686-pc-mingw32 command then checking build system type... i686-pc-mingw32 checking host system type... i686-pc-mingw32 checking target system type... xyz-mingw32... (3 Replies)
Discussion started by: Heeka
3 Replies

3. Shell Programming and Scripting

ERROR in executing mysql querys in shell scripting

Hi All, Please see the below script for mysql 3 commands. Its giving me the right output for all three commands but showing some errors in first two commands , i guess there might be an issue with date. Can anyone help me . #! /bin/bash TABLE_NAME=testingddatabase USER_NAME=root... (3 Replies)
Discussion started by: aish11
3 Replies

4. Shell Programming and Scripting

shell scripting error help

Im tryign to write a script that counts the number of new lines in the file with the most new lines in a given directory i keep getting this error /export/home/sieben01/itec400/homework> ./maxlines.sh ./maxlines.sh: syntax error: `then' unexpected operator/operand any ideas? ... (11 Replies)
Discussion started by: livewire06
11 Replies

5. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

6. Shell Programming and Scripting

Error handling in Unix shell scripting

Hello, I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log set pagesize 0 set feedback off set heading off set linesize 200... (1 Reply)
Discussion started by: rksingh003
1 Replies

7. Shell Programming and Scripting

bash shell scripting error need help urgently

#! /bin/sh abcd = "Hello world" if then echo $abcd fi i got error message that line3 : abcd: command not found line5 : [0: command not found line5 : [1: command not found i have no idea why i got this message. Can some one help me ??? (6 Replies)
Discussion started by: bonosungho
6 Replies

8. Shell Programming and Scripting

shell scripting error

i am trying to work on a simple shell script as #!/bin/bash filename = $2 if ; then echo " Displaying the Content of the file:" filename = $2 cat filename else if ; then echo "Displaying directory listing:" ls -l filename else echo " Commands not correct:" fi done it shows the... (3 Replies)
Discussion started by: phone_book
3 Replies

9. Shell Programming and Scripting

Shell Scripting Error

When i run the script firecall.sh,i am getting a weird error. root: ./var/ADMIN/bin/firecall.sh d12381 ./var/ADMIN/bin/firecall.sh: ?osrc: command not found ./var/ADMIN/bin/firecall.sh: ?osrc: command not found The script is successful,but the error interests me...Any Ideas?? The... (1 Reply)
Discussion started by: Renjesh
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question