Solved

script in bash

Posted on 2003-11-21
10
673 Views
Last Modified: 2008-02-01
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
Comment
Question by:aot2002
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9801901
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
 

Expert Comment

by:S_KuMaaaaR
ID: 9822630

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
 
LVL 1

Author Comment

by:aot2002
ID: 9826028
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 5

Expert Comment

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

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9864333
yep ... that can cause funny things too ...
use dos2unix filename
and then execute the script
0
 
LVL 1

Expert Comment

by:ramses0
ID: 10002705
also make sure it is chmod +x

--Robert
0
 
LVL 1

Author Comment

by:aot2002
ID: 10002887
found the only way to run it was to call the bash command then the name of the script.
0
 
LVL 1

Accepted Solution

by:
ramses0 earned 35 total points
ID: 10003046
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
 
LVL 1

Author Comment

by:aot2002
ID: 10003063
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question