Link to home
Start Free TrialLog in
Avatar of aot2002
aot2002

asked on

script in bash

im working on a script file which is giving me trouble in the debian distro
heres the file


#!/bin/sh
#read file then prepare with primary key then import the file into the database
mount /mnt/cdrom #mount cdrom
cp /mnt/cdrom/AD.AP /home/mysql/AD.AP #copy the file to a location
cd /home/mysql #switch directory
rm -f AD6602.txt #remove old file
i=0 #counter variable
cat AD.AP | while read line #read file and loop through it
do
echo "$i,$line" >> AD6602.txt #send line into file
let i++ #increase counter
done #stop
umount /mnt/cdrom #finished with cdrom
mysql -u root -p < scriptimport.txt
mysqlimport -u root -p allmydata AD6602.txt


worse part is it wont execute properly in debian enviroment on redhat its fine?
i get end of file unexpected and i use the -x and i get a debugging of the While statement not working.. keeps saying that the end of file is unexpected
Avatar of sunnycoder
sunnycoder
Flag of India image

the script looks OK and it is running fine on one linux distribution ... clearly there are some issues with the implementation of sh on the debian distro ... However, I am not aware of them ...

I would try the following ...
1. changing let to expr
2. adding/removing a newline at the end of the script ... this sounds absurd but worked for me once on some distro (I was having the same problem)... I still dont know why or how.
Avatar of S_KuMaaaaR
S_KuMaaaaR


Try using following loop.... Instead of piping the cat command use redirection operator....

i=0
while read line #read file and loop through it
do
echo "$i,$line" >> AD6602.txt #send line into file
let i++ #increase counter
done  < AD.DP #stop

Sanjeev.
Avatar of aot2002

ASKER

S_KuMaaaaR &  sunnycoder

no the script just wont execute!
the script runs on another machine just wont run on this debian one i have

Last time I had this problem,
it was because the file contains CR LF  (DOS things you know).

yep ... that can cause funny things too ...
use dos2unix filename
and then execute the script
also make sure it is chmod +x

--Robert
Avatar of aot2002

ASKER

found the only way to run it was to call the bash command then the name of the script.
ASKER CERTIFIED SOLUTION
Avatar of ramses0
ramses0

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial