Solved

script in bash

Posted on 2003-11-21
10
650 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
Last time I had this problem,
it was because the file contains CR LF  (DOS things you know).

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 45

Expert Comment

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

Expert Comment

by:ramses0
Comment Utility
also make sure it is chmod +x

--Robert
0
 
LVL 1

Author Comment

by:aot2002
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

10 Experts available now in Live!

Get 1:1 Help Now