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
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
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.
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
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).
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
use dos2unix filename
and then execute the script
also make sure it is chmod +x
--Robert
--Robert
ASKER
found the only way to run it was to call the bash command then the name of the script.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
https://www.experts-exchange.com/questions/20835047/change-accepted-answer-to-ramseo.html
thanks ramseo
your right it worked
thanks ramseo
your right it worked
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.