LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2010, 06:13 AM   #16
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92

Hi,

Add the following line before line number 2 in your script and run (don't remove line number 2):

Code:
/bin/pwd
 
Old 06-01-2010, 07:25 AM   #17
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Ok, I have removed the screen command until I have the .sh working

This is my current .sh
Code:
/bin/pwd
cd bin
echo Press Crtl + A + D to detach!
java -Xmx300m -cp .:./bin.:./deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar server.Server -server
The output:
Code:
[server@agentblue ~]$ ./run.sh
: No such file or directory
: No such file or directory
Press Crtl + A + D to detach!
Exception in thread "main" java.lang.NoClassDefFoundError: server/Server
Caused by: java.lang.ClassNotFoundException: server.Server
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
[server@agentblue ~]$
 
Old 06-01-2010, 07:29 AM   #18
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Hi

You do have the following as your first line right?

Code:
#!/bin/bash
or

Code:
#!/bin/sh
Remove/Comment out all the lines except the /bin/pwd - this should output the present working directory when you run the script.
 
Old 06-01-2010, 07:32 AM   #19
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Hi

You do have the following as your first line right?

Code:
#!/bin/bash
or

Code:
#!/bin/sh
Remove/Comment out all the lines except the /bin/pwd - this should output the present working directory when you run the script.
I don't have any #!/bin/ script at the top.

Here is my current .sh now
Code:
#!/bin/bash
#cd bin
/bin/pwd
#echo Press Crtl + A + D to detach!
#java -Xmx300m -cp .:./bin.:./deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar server.Server -server
Output:
Code:
[server@agentblue ~]$ ./run.sh
-bash: ./run.sh: /bin/bash^M: bad interpreter: No such file or directory
[server@agentblue ~]$
Here is an output with '#!/bin/sh'

Code:
[server@agentblue ~]$ ./run.sh
-bash: ./run.sh: /bin/sh^M: bad interpreter: No such file or directory
[server@agentblue ~]$
 
Old 06-01-2010, 07:37 AM   #20
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Hi

One of the questions I should have asked right at the start - what distro and version are you using?

Also post the output of:

Code:
#which bash

#which sh
 
Old 06-01-2010, 07:39 AM   #21
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Hi

One of the questions I should have asked right at the start - what distro and version are you using?

Also post the output of:

Code:
#which bash

#which sh
OS: centos-5-x86

which bash output:
Code:
[server@agentblue ~]$ which bash
/bin/bash
[server@agentblue ~]$
which sh output:
Code:
[server@agentblue ~]$ which sh
/bin/sh
[server@agentblue ~]$
 
Old 06-01-2010, 07:44 AM   #22
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
The only reason I can think of that not working is that /bin is not in your "server" user's path.

I'm running an identical script (below) on a RHEL 5 (CentOS is a clone of RHEL) instance, and it works perfectly.

Code:
#!/bin/bash
/bin/pwd
Maybe post the output of:

Code:
# echo $PATH
and

Code:
#which pwd
 
Old 06-01-2010, 07:46 AM   #23
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
The only reason I can think of that not working is that /bin is not in your "server" user's path.

I'm running an identical script (below) on a RHEL 5 (CentOS is a clone of RHEL) instance, and it works perfectly.

Code:
#!/bin/bash
/bin/pwd
Maybe post the output of:

Code:
# echo $PATH
and

Code:
#which pwd
Humm. Weird.

Output of $PATH
Code:
[server@agentblue ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/home/server/bin
[server@agentblue ~]$
Output of which pwd
Code:
[server@agentblue ~]$ which pwd
/bin/pwd
[server@agentblue ~]$
I ran that script you posted;

Code:
[server@agentblue ~]$ ./test.sh
-bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory
[server@agentblue ~]$

Last edited by IJustinI; 06-01-2010 at 07:48 AM.
 
Old 06-01-2010, 07:52 AM   #24
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Did you edit that script on a Windows machine?

This could have caused this issue - check this post here: http://www.linuxquestions.org/questi...ectory-461400/

Use vim on the Linux machine itself (don't edit in Windows and cut and paste) and recreate the script to run the /bin/pwd part.
 
Old 06-01-2010, 07:55 AM   #25
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Did you edit that script on a Windows machine?

This could have caused this issue - check this post here: http://www.linuxquestions.org/questi...ectory-461400/

Use vim on the Linux machine itself (don't edit in Windows and cut and paste) and recreate the script to run the /bin/pwd part.
Yes I am using a windows machine to edit the scripts.

I had a look at that topic and I don't fully understand it, sorry
 
Old 06-01-2010, 07:58 AM   #26
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Windows terminates lines in a different way. When you get them back on the Linux machine use

Code:
dos2unix <script>
(If installed) to fix this.
 
1 members found this post helpful.
Old 06-01-2010, 07:58 AM   #27
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Basically when you create a script in a Windows/DOS environment, and cut and paste into a Linux environment it pulls across certain characters which cause the compilation error you were having.

In summary, use the vi/vim editor and manually type in the script.
 
Old 06-01-2010, 08:01 AM   #28
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Basically when you create a script in a Windows/DOS environment, and cut and paste into a Linux environment it pulls across certain characters which cause the compilation error you were having.

In summary, use the vi/vim editor and manually type in the script.
I used vim to edit test.sh
I found no other characters inside the script.
I deleted everything and re-typed it. I still get the same error.

Are you able to use "Teamviewer" to view my computer and see what is wrong?

Edit: I install dos2unix and converted test.sh
this is the output;

Code:
[server@agentblue ~]$ dos2unix test.sh
dos2unix: converting file test.sh to UNIX format ...
[server@agentblue ~]$ ./test.sh
/home/server
[server@agentblue ~]$

Last edited by IJustinI; 06-01-2010 at 08:03 AM.
 
Old 06-01-2010, 08:06 AM   #29
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Quote:
[server@agentblue ~]$ dos2unix test.sh
dos2unix: converting file test.sh to UNIX format ...
[server@agentblue ~]$ ./test.sh
/home/server
[server@agentblue ~]$
OK great, this means the dos2unix command worked. Now add in the other lines that you commented out in run.sh and try to run it (after doing the dos2unix conversion)...
 
1 members found this post helpful.
Old 06-01-2010, 08:08 AM   #30
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
OK great, this means the dos2unix command worked. Now add in the other lines that you commented out in run.sh and try to run it (after doing the dos2unix conversion)...
Thankyou very much.
Everything is working now!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 09:31 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 04:47 AM


All times are GMT -5. The time now is 11:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration