LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-26-2014, 06:49 AM   #1
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Rep: Reputation: Disabled
Script Fails on Crunchbang


Hi, I'm brand new to Linux and struggling (really struggling). Hope I can get a solution to my problem

I want to run a script on Crunchbang. I always get Cannot Access: No Such File or directory.

A search indicates that there maybe <cr><lf> characters in the script which might be a problem. There are. I used a hex editor to take out the <lf> but still no good (worse).

The script file has only ever been produced in a Linux environment (Crunchbang nedit).

All of the files it requires are there, but the script doesn't resolve. he commands can be executed individually, no problems. But the script always fails, as though it's running from another planet...

Here is a paste of the script, with debug statements etc:
________________________________
echo "start of test script"
echo "Audio file to be played" "$1"
echo "(-0-)"
echo "Path" $PATH
echo "(-1-)"
which aplay
echo "(-2-)"
echo "sending ls -l d1"
ls -l "$1"
echo "(-3-)"
echo "sending: ls -l aplay"
ls -l /usr/bin/aplay
echo "(-4-)"
echo "sending: /usr/bin/aplay d1"
/usr/bin/aplay "$1"
echo "(-5-)"
echo "end of test script"
____________________________________

Here is a paste of what it produces
Note: I ran the command as:
./test_script //usr/mms/cfg/audio_files/12-1-10-1 &> testscriptout.txt

____________________________________

start of test script
Audio file to be played //usr/mms/cfg/audio_files/12-1-10-1
(-0-)
Path /home/transcend/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
(-1-)
(-2-)
sending ls -l d1
ls: cannot access //usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-3-)
sending: ls -l aplay
ls: cannot access
: No such file or directory
-rwxr-xr-x 1 root root 59368 Jan 10 2013 /usr/bin/aplay
(-4-)
sending: /usr/bin/aplay d1
//usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-5-)
end of test script

_________________________________________

Notice no output between (1) and (2) but at a command prompt "which aplay" shows "/usr/bin/aplay"

Notice between (3) and (4) where it sends "ls -l /usr/bin/aplay"
two responses:
ls: cannot access
: No such file or directory
and then:
-rwxr-xr-x 1 root root 59368 Jan 10 2013 /usr/bin/aplay

Maybe this is a crunchbang thing?

Weeks of trying, I'm turning to you experts for a resolution
Thanks
VideoTrack
 
Old 03-26-2014, 08:11 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,737

Rep: Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921
Your basic syntax error is the double //
Quote:
//usr/mms/cfg/audio_files/12-1-10-1.
Should be assuming the rest of the path is correct.
Quote:
/usr/mms/cfg/audio_files/12-1-10-1
 
Old 03-26-2014, 08:51 AM   #3
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thank you michaelk for your suggestion. Im sure that was tried before, but in hope it would resolve, I did exactly what you suggested:

Here is the output when I type the exact command:
./test_script /usr/mms/cfg/audio_files/12-1-10-1 &> testscript1out.txt
_______________________________________________

start of test script
Audio file to be played /usr/mms/cfg/audio_files/12-1-10-1
(-0-)
Path /home/transcend/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
(-1-)
(-2-)
sending ls -l d1
ls: cannot access /usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-3-)
sending: ls -l aplay
ls: cannot access
: No such file or directory
-rwxr-xr-x 1 root root 59368 Jan 10 2013 /usr/bin/aplay
(-4-)
sending: /usr/bin/aplay d1
/usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-5-)
end of test script
_______________________________________________

Did this work for you OK?

I'm also thinking your kind suggestion had nothing to do with the "which aplay" command between (1) and (2) which results in nothing. Would that be correct?

I truly hope somebody can help
VideoTrack

Last edited by VideoTrack; 03-26-2014 at 08:57 AM.
 
Old 03-26-2014, 09:07 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,737

Rep: Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921Reputation: 5921
Lets start with the first error.

Your still getting a file not found error with "/usr/mms/cfg/audio_files/12-1-10-1"

Have you confirmed this is a valid /path/filename? If it exits does your username have the proper permissions to read the file?

Last edited by michaelk; 03-26-2014 at 09:13 AM. Reason: Not thinking...
 
Old 03-26-2014, 09:25 AM   #5
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
If I type:

aplay /usr/mms/cfg/audio_files/12-1-10-1

I hear the wav file played on the speaker
Note that 12-1-10-1 is a soft link to another file: test.wav
I've tried both the link and the file directly - there is no difference, neither work.

Here is my steps:
I type: aplay /usr/mms/cfg/audio_files/12-1-10-1
Screen displays: Playing WAVE '/usr/mms/cfg/audio_files/12-1-10-1' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

I hear the wav file being played

After a few seconds when the file has completed, my command prompt is returned.

If I just type aplay<enter>, I get a blank line and nothing, I have to eventually type ^C, and then I get:
^CAborted by signals Interrupt...

If I type "which aplay" I get:
/usr/bin/aplay

file: test_script is set with execute privileges as follows for "ls -l test_script"
-rwxr-xr-x 1 transcend transcend 354 Mar 26 21:35 test_script

Thank you for your continued support, it is appreciated.
VideoTrack
 
Old 03-26-2014, 09:44 AM   #6
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
michaelk, thanks for your continued support

re: Have you confirmed this is a valid /path/filename?
If I type at a command prompt:
ls -l /usr/mms/cfg/audio_files/12-1-10-1
I get:
lrwxrwxrwx 1 transcend transcend 35 Apr 14 2013 /usr/mms/cfg/audio_files/12-1-10-1 -> test.wav

re: If it exists does your username have the proper permissions to read the file?
Sorry, I don't know how to do that, I did presume that the lrwxrwxrwx status would be OK

Many thanks
VideoTrack
 
Old 03-26-2014, 09:58 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Your last post show the permissions of the link, which is generally as you posted for all links so that it can accurately reflect whatever the original file has.
So we would need the permissions of the original file to know if you have access or not

Now I didn't see it asked anywhere, so my first question is ... what sort of script is this? You say you are running it like so:
Code:
./test_script /usr/mms/cfg/audio_files/12-1-10-1 &> testscript1out.txt
Yet I do not see the first line of your script to identify what shell to use (assuming a shell script)?
If this first line does not exist, this would be a first issue

Also, as above, please use [code][/code] tags when showing code or data to make it easier to read.

Now assuming you do have the interpreter line in your script and that it is possibly a bash script, place the following as the second line in the script:
Code:
set -xv
When you next re-run the script it will show what happens as it calls every line of the script and what the output is. This should help you pinpoint where your issue lies.

If not , let us see the output and we will attempt to help further
 
1 members found this post helpful.
Old 03-26-2014, 10:21 AM   #8
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Hello grail, thank you for your support
The file is a simple ascii file, the entire contents are below (with code tags, thanks for the advice). I eventually want to call if from a C program, but it doesn't even work at command prompt. The ascii file is simply named 'test_script'.

I eventually want to call it in C using something like execv( "/bin/sh", argv );

At the moment I am just calling it from the command line, exacly like I listed above

You mentioned:
"Yet I do not see the first line of your script to identify what shell to use (assuming a shell script)? If this first line does not exist, this would be a first issue"
Unfortunately, and regrettably,I am not familiar with what you are explaining here.


Code:
echo "start of test script"
echo "Audio file to be played" "$1"
echo "(-0-)"
echo "Path" $PATH
echo "(-1-)"
which aplay
echo "(-2-)"
echo "sending ls -l d1"
ls -l "$1"
echo "(-3-)"
echo "sending: ls -l aplay"
ls -l /usr/bin/aplay 
echo "(-4-)"
echo "sending: /usr/bin/aplay d1"
/usr/bin/aplay "$1"
echo "(-5-)"
echo "end of test script"
I edited as suggested, now the script looks like this:
Code:
echo "start of test script"
set -xv
echo "Audio file to be played" "$1"
echo "(-0-)"
echo "Path" $PATH
echo "(-1-)"
which aplay
echo "(-2-)"
echo "sending ls -l d1"
ls -l "$1"
echo "(-3-)"
echo "sending: ls -l aplay"
ls -l /usr/bin/aplay 
echo "(-4-)"
echo "sending: /usr/bin/aplay d1"
/usr/bin/aplay "$1"
echo "(-5-)"
echo "end of test script"
This is the output:
_______________________________________
start of test script
./test_script: line 2: set: -
: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
Audio file to be played /usr/mms/cfg/audio_files/12-1-10-1
(-0-)
Path /home/transcend/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
(-1-)
(-2-)
sending ls -l d1
ls: cannot access /usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-3-)
sending: ls -l aplay
ls: cannot access
: No such file or directory
-rwxr-xr-x 1 root root 59368 Jan 10 2013 /usr/bin/aplay
(-4-)
sending: /usr/bin/aplay d1
/usr/mms/cfg/audio_files/12-1-10-1
: No such file or directory
(-5-)
end of test script
_________________________________

Thank you again

VideoTrack
 
Old 03-26-2014, 10:30 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
try adding a line like:
Code:
#!/bin/bash
as the first line. this tells the interpreter to specifically invoke the bash shell to parse the script.


also, try running this:
Code:
cat -A test_script

Last edited by schneidz; 03-26-2014 at 10:34 AM.
 
1 members found this post helpful.
Old 03-26-2014, 10:47 AM   #10
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thank you schneidz

Here is the code now

Code:
#!/bin/bash
echo "start of test script"
set -xv
echo "Audio file to be played" "$1"
echo "(-0-)"
echo "Path" $PATH
echo "(-1-)"
which aplay
echo "(-2-)"
echo "sending ls -l d1"
ls -l "$1"
echo "(-3-)"
echo "sending: ls -l aplay"
ls -l /usr/bin/aplay 
echo "(-4-)"
echo "sending: /usr/bin/aplay d1"
/usr/bin/aplay "$1"
echo "(-5-)"
echo "end of test script"
if I type manually "which bash" I get:
/bin/bash

when I run the script by typing: ./test_script /usr/mms/cfg/audio_files/12-1-10-1
I get:
Code:
bash: ./test_script: /bin/bash^M: bad interpreter: No such file or directory
when I type cat -A test_script, I get
Code:
#!/bin/bash^M$
echo "start of test script"^M$
set -xv^M$
echo "Audio file to be played" "$1"^M$
echo "(-0-)"^M$
echo "Path" $PATH^M$
echo "(-1-)"^M$
which aplay^M$
echo "(-2-)"^M$
echo "sending ls -l d1"^M$
ls -l "$1"^M$
echo "(-3-)"^M$
echo "sending: ls -l aplay"^M$
ls -l /usr/bin/aplay ^M$
echo "(-4-)"^M$
echo "sending: /usr/bin/aplay d1"^M$
/usr/bin/aplay "$1"^M$
echo "(-5-)"^M$
echo "end of test script"^M$
Thank you for your support for this issue.
VideoTrack
 
Old 03-26-2014, 10:55 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
those ^m's represent ms-windows cr-lf's instead of the unix/linux/bsd/sun-os/mac/... standard lf for terminating lines.

kind of surprising since you mention you are not editing this in windows. maybe copy-pasting it from something like a web browser is messing with it ?


do you have dos2unix installed on your machine ?

Last edited by schneidz; 03-26-2014 at 11:03 AM.
 
1 members found this post helpful.
Old 03-26-2014, 11:08 AM   #12
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Aside from the file conversion.. i would use:

Code:
echo `which bash`
instead.
 
Old 03-26-2014, 06:56 PM   #13
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks you schneidz, I installed dos2unix and ran it across the file, and the file now runs. The file was an email attachment downloaded from a Windows system, but never edited there, so I don't know if that's where it got converted, but your suggestion has resolved that part. Thanks again.

I called my script directly, and it worked, and played the file.
Here is the output:
Code:
start of test script
Audio file to be played /usr/mms/cfg/audio_files/12-1-10-1
(-0-)
Path /home/transcend/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
(-1-)
/usr/bin/aplay
(-2-)
sending ls -l d1
lrwxrwxrwx 1 transcend transcend 35 Apr 14  2013 /usr/mms/cfg/audio_files/12-1-10-1 -> TrafficInformationalTestMessage.wav
(-3-)
sending: ls -l aplay
-rwxr-xr-x 1 root root 59368 Jan 10  2013 /usr/bin/aplay
(-4-)
sending: /usr/bin/aplay d1
Playing WAVE '/usr/mms/cfg/audio_files/12-1-10-1' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
(-5-)
end of test script
However, my next problem
When I call the script from my program, I get some sort of alsa library or aplay error, I hope this is resolvable.

PulseAudio: Unable to connect: Connection refused

aplay: main:682: audio open error: Connection refused

The output shows the following:
Code:
start of test script
Audio file to be played /usr/mms/cfg/audio_files/12-1-10-1
(-0-)start of test script
Audio file to be played /usr/mms/cfg/audio_files/12-1-10-1
(-0-)
Path /sbin:/usr/sbin:/bin:/usr/bin:/bin
(-1-)
/usr/bin/aplay
(-2-)
sending ls -l d1
lrwxrwxrwx 1 transcend transcend 35 Apr 14  2013 /usr/mms/cfg/audio_files/12-1-10-1 -> TrafficInformationalTestMessage.wav
(-3-)
sending: ls -l aplay
-rwxr-xr-x 1 root root 59368 Jan 10  2013 /usr/bin/aplay
(-4-)
sending: /usr/bin/aplay d1
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

aplay: main:682: audio open error: Connection refused
(-5-)
end of test script
Many thanks for your continued support
VideoTrack

Last edited by VideoTrack; 03-26-2014 at 07:05 PM. Reason: typo error
 
Old 03-26-2014, 07:52 PM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
ummmm ... I am confused?? The first part of the last post seems to say it works fine and then the second that it does not,
yet from what I can see all the details are the same????

Have I missed something?


Wait a sec, just spotted that in the second one you are running the script as someone else, due to the different PATH
information ... and as a betting man I would say you are running it as root. Is this correct?
If not, who is the second user?
 
Old 03-26-2014, 08:13 PM   #15
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i am confused as well. a few posts ago, op mentioned of calling the bash script from within a c-program using execvp(). which is kinda' strange (but not impossible) considering most of the time people create shell scripts to call c-programs.

i would bet that similar to running it in cron only a limited set of environment variables are invoked therefore its not passing everything.

Last edited by schneidz; 03-26-2014 at 08:36 PM.
 
  


Reply



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
ath9k driver fails on Crunchbang after certain amount of time (Acer Aspire) Rainfly_X Linux - Hardware 2 11-23-2012 11:45 PM
[SOLVED] Script Fails maddyfreaks Linux - Newbie 7 05-02-2011 01:25 PM
What if a script inside another script fails to run? saiteju Programming 3 02-02-2010 11:35 PM
Shutdown script for Crunchbang Linux running from USB on Asus Surf 2G Maestro01 Linux - Laptop and Netbook 5 03-19-2009 11:11 AM
install script fails sycamorex Linux - Software 2 06-16-2007 04:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 AM.

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
Open Source Consulting | Domain Registration