Solved

script in bash

Posted on 2003-11-21
10
657 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expect & sshpass package for Solaris 10 x86 15 893
automating commands in linux on start up 2 45
Unix / Linux grid computing 5 144
Ubuntu 16.04 Emergency Boot 2 168
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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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