Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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
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
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:
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
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
_________________________________
#!/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
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
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.