Solved

script in bash

Posted on 2003-11-21
10
663 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now