• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

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
0
aot2002
Asked:
aot2002
  • 3
  • 2
  • 2
  • +2
1 Solution
 
sunnycoderCommented:
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.
0
 
S_KuMaaaaRCommented:

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.
0
 
aot2002Author Commented:
S_KuMaaaaR &  sunnycoder

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

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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

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

--Robert
0
 
aot2002Author Commented:
found the only way to run it was to call the bash command then the name of the script.
0
 
ramses0Commented:
One thing that's different about debian is that (usually) the current directory is not part of the default path.

Try this too:

  chmod +x myscript.sh
  ./myscript.sh

(you can't just type "myscript.sh" because debian won't find it as an executable).

This is a "security feature" of debian... in that an evil haxor can't put a script called "ls" in some directory and have you accidently run it if you are in that directory and type ls.  "ls" is the system ls, "./ls" is: "the ls that's in this current directory that I'm in".

--Robert
0
 
aot2002Author Commented:
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now