openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting » Console Ls Works, Bash Script Ls Gives File Not Found

Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc

 
Page 1 of 2 1 2
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 27-Jan-2008, 11:07
Neophyte42
Guest
 
Posts: n/a
Default

I have an environment variable exported from .bashrc that is a directory, let's call this variable DIRECTORY.

When in a console I enter:

ls $DIRECTORY

I get the correct ls results, but when I execute this command from inside of a bash script I get a "No such file or directory" error.

Any advice will be appreciated as I am very frustrated. I am running SUSE 10.2 64-bit on a dual opteron workstation. To add insult to injury, the directory in question is an NFS share and the non-local machines can access the directory just fine from within bash scripts, only the local node cannot seem to see it's own local directory.

Thanks!
  #2 (permalink)  
Old 27-Jan-2008, 15:04
ken_yap
Guest
 
Posts: n/a
Default

Where is your bash script executed from? A cron job?

What do you get when you put a line:

echo $DIRECTORY

before the ls?
  #3 (permalink)  
Old 28-Jan-2008, 11:38
Neophyte42
Guest
 
Posts: n/a
Default

Quote:
Where is your bash script executed from? A cron job?

What do you get when you put a line:

echo $DIRECTORY

before the ls?
[/b]
The script is not a cron job, it is just a text file containing several commands. Originally I was going to set up two long runtime programs to use the directory in question and did some troubleshooting to find the behavior I mentioned. I call the script from the command line by ./SCRIPTFILE.

For both console and script, echo $DIRECTORY gives the expected result, but only console gives the correct result for ls $DIRECTORY.
  #4 (permalink)  
Old 28-Jan-2008, 11:41
ambidextrous
Guest
 
Posts: n/a
Default

Do you get the same error when you say inside the script

/usr/bin/ls $DIRECTORY

?
  #5 (permalink)  
Old 28-Jan-2008, 13:59
ken_yap
Guest
 
Posts: n/a
Default

It's in /bin/ls actually.

OP, exactly what is not found? The ls command or the directory?
  #6 (permalink)  
Old 28-Jan-2008, 15:14
Neophyte42
Guest
 
Posts: n/a
Default

Quote:
It's in /bin/ls actually.

OP, exactly what is not found? The ls command or the directory?
[/b]
The directory is not found. As I recall, I also attempted to do ls /the/actual/explicit/path and had the same result - the directory can be found when called from the console directly but not when called from a shell script.

I even made a new directory on the same [nfs shared] directory and had the same results. I have not yet tried to do ls / from a script to determine if it is just an issue with the partition that the nfs share is on.

Other networked machines can see the nfs share without issue even from shell scripts - only the machine that the nfs share is local to can't find it from scripts.
  #7 (permalink)  
Old 28-Jan-2008, 18:28
Neophyte42
Guest
 
Posts: n/a
Default

Ok, I tried

ls /

to rule out some nfs quirk and get the same response (from console I can see everything, from script I get "No such file or directory")..

I have other network computers using the nfs share right now so I can't reboot. Hmm... I can't even log off and then back on since I started the job by ssh.

  #8 (permalink)  
Old 28-Jan-2008, 21:37
ken_yap
Guest
 
Posts: n/a
Default

Is this machine running some sort of selinux or apparmor environment?
  #9 (permalink)  
Old 29-Jan-2008, 07:38
Neophyte42
Guest
 
Posts: n/a
Default

Quote:
Is this machine running some sort of selinux or apparmor environment?
[/b]
Not that I am aware of. If these security applications come as part of the downloadable SUSE 10.2 64-bit DVD then it is possible. However, I have not gone out of my way to find these applications (in fact, I had to Google them to find out what they were).
  #10 (permalink)  
Old 29-Jan-2008, 10:09
Hieronymous
Guest
 
Posts: n/a
Default

So you're saying that 'ls /' from within the script gives a 'ls: cannot access /: No such file or directory' error? That seems pretty unlikely. Can you show us the entire script?
 
Page 1 of 2 1 2

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2