LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-11-2020, 09:42 AM   #1
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Rep: Reputation: Disabled
File turns into a directory error


Hi,

Recently I have encountered a bug in my Linux kernel.

I am trying to perform the following command in my startup script called example.sh:

echo 1 > /var/opt/lab/example.log

5 out of 100 times in my Syslog I captured:

It shows me this error:

/usr/bin/example.sh: line 494: /var/opt/lab/example.log : Is a directory

From my understanding, i dont think this is possible.

I hope anyone can share some ideas with me.

I have two scripts called script A and script B let's say:
######################################Script A#################################
The logic in my script is this:
i will provide more detail here:
every time restart I need to check a flag file called flag which is in the same directory /var/opt/lab/
this flag only used once, once it's been detected i will do

if [ -d "/var/opt/lab/flag" ]; then
rm -rf /var/opt/lab/*
echo "Delete Factory files."
fi

then I also do:

if [ ! -d "/var/opt/lab/" ]; then
mkdir -p /var/opt/lab
echo "/var/opt/lab created"
else
echo "/var/opt/lab already exists"
fi

during normal operation the flag file is deleted then :
VALUE can be either 0 or 1 depends on the register value I read

echo "${VALUE}" > /var/opt/lab/example.log

##################Script B###################################
INDEX=`cat /var/opt/lab/example.log` ---------------------------------------------------> This is where the error raised: says it's a directory not a file

Based on the INDEX i will do different operations.
###########################################################################

[QUESTION]I can not determine where does this example.log directory comes from I need tips on trouble shoot this. Is it linux kernel driver related ?

Best Regards,
Jiye

Last edited by jy824212; 08-13-2020 at 12:53 PM.
 
Old 08-11-2020, 09:50 AM   #2
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Code:
echo 1 > /var/log/lab/example.log
&
Code:
/usr/bin/example.sh: line 494: /var/opt/lab/ example.log : Is a directory
are two different things
 
Old 08-11-2020, 09:51 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Well, it is quite possible that /var/log/lab/example.log is a directory. For example:
Code:
rm -rf /var/log/lab/example.log
mkdir -p /var/log/lab/example.log
and voila, /var/log/lab/example.log is a directory.

The question is, where does this directory come from. I can't tell.

In your script, you could add code like this:
Code:
if [ -d /var/log/lab/example.log ]
then 
    echo /var/log/lab/example.log is a directory
else
    echo 1 > /var/log/lab/example.log
fi
 
Old 08-11-2020, 09:53 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Honest Abe View Post
Code:
echo 1 > /var/log/lab/example.log
&
Code:
/usr/bin/example.sh: line 494: /var/opt/lab/ example.log : Is a directory
are two different things
Ha! I didn't catch this.

One is /var/log/lab. The other, /var/opt/lab. I assume that the space before example.log is a typo.
 
Old 08-11-2020, 10:05 AM   #5
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Honest Abe View Post
Code:
echo 1 > /var/opt/lab/example.log
&
Code:
/usr/bin/example.sh: line 494: /var/opt/lab/ example.log : Is a directory
are two different things
echo 1 > /var/log/lab/example.log is called from line 494 of my example.sh script

Last edited by jy824212; 08-11-2020 at 10:06 AM.
 
Old 08-11-2020, 10:07 AM   #6
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Honest Abe View Post
Code:
echo 1 > /var/log/lab/example.log
&
Code:
/usr/bin/example.sh: line 494: /var/opt/lab/ example.log : Is a directory
are two different things
sorry it's a typo should be echo 1 > /var/opt/lab/example.log
 
Old 08-11-2020, 10:08 AM   #7
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Ha! I didn't catch this.

One is /var/log/lab. The other, /var/opt/lab. I assume that the space before example.log is a typo.
yes, it's a typo and I already fixed it.
 
Old 08-11-2020, 10:12 AM   #8
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Well, it is quite possible that /var/log/lab/example.log is a directory. For example:
Code:
rm -rf /var/log/lab/example.log
mkdir -p /var/log/lab/example.log
and voila, /var/log/lab/example.log is a directory.

The question is, where does this directory come from. I can't tell.

In your script, you could add code like this:
Code:
if [ -d /var/log/lab/example.log ]
then 
    echo /var/log/lab/example.log is a directory
else
    echo 1 > /var/log/lab/example.log
fi

yes that is my really confusion I want to address here, how comes it can be a directory if I only generated it as a file?
 
Old 08-11-2020, 10:58 AM   #9
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Quote:
Originally Posted by jy824212 View Post
yes that is my really confusion I want to address here, how comes it can be a directory if I only generated it as a file?
to expand on what @berndbausch has already said, refer to this : https://www.tldp.org/LDP/abs/html/fto.html

and a 'ls -l' should tell you if it is a directory or a file.
 
Old 08-11-2020, 11:00 AM   #10
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Honest Abe View Post
to expand on what @berndbausch has already said, refer to this : https://www.tldp.org/LDP/abs/html/fto.html

and a 'ls -l' should tell you if it is a directory or a file.
my question here is not to determine if it's a directory or a file.

I am trying to seek for the solution of why the file system generates a directory when I actually created a file
 
Old 08-11-2020, 11:25 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Sorry, but is it /var/log/lab/example.log or /var/opt/lab/example.log now? In your script?
And are you sure there isn't a space between /var/.../lab/ and example.log, like so:
Code:
/var/.../lab/ example.log
???

Impossible to say anything further without knowing what else has access to that file. I assume you have "anonymised" that output for us?
Are you using /var/.../lab/example.log only once throughout the whole script, just to echo a "1" into it?
What else uses this file? What does it log?
 
Old 08-11-2020, 11:43 AM   #12
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
Sorry, but is it /var/log/lab/example.log or /var/opt/lab/example.log now? In your script?
And are you sure there isn't a space between /var/.../lab/ and example.log, like so:
Code:
/var/.../lab/ example.log
???

Impossible to say anything further without knowing what else has access to that file. I assume you have "anonymised" that output for us?
Are you using /var/.../lab/example.log only once throughout the whole script, just to echo a "1" into it?
What else uses this file? What does it log?
It's /var/opt/lab/example.log now
Was a typo and I fixed it
(1) There is no space /var/opt/lab/example.log
(2)
The logic in my script is this:
i will provide more detail here:
every time restart I need to check a flag file called flag which is in the same directory /var/opt/lab/
this flag only used once, once it's been detected i will do

if [ -d "/var/opt/lab/flag" ]; then
rm -rf /var/opt/lab/*
echo "Delete Factory files."
fi

then I also do:

if [ ! -d "/var/opt/lab/" ]; then
mkdir -p /var/opt/lab
echo "/var/opt/lab created"
else
echo "/var/opt/lab already exists"
fi

during normal operation the flag file is deleted then :
VALUE can be either 0 or 1 depends on the register value I read

echo "${VALUE}" > /var/opt/lab/example.log
INDEX=`cat /var/opt/lab/example.log` ---------------------------------------------------> This is where the error raised: says it's a directory not a file

Based on the INDEX i will do different operations.

Last edited by jy824212; 08-11-2020 at 11:48 AM.
 
Old 08-11-2020, 12:22 PM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Code:
ls -al /var/opt/lab/example.log
please.

And no other process ever accesses/writes to /var/opt/lab/ and/or /var/opt/lab/example.log???

Since you are creating that directory in your script, it is really very likely that you did something wrong in your script.

Do more troubleshooting, e.g.:

1. add
Code:
set -xv
as the 2nd line of your script (right under the #!/bin/bash).

2. Try saving example.log to another directory, one you do not constantly create/delete.
 
Old 08-13-2020, 10:22 AM   #14
jy824212
Member
 
Registered: Dec 2017
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
Code:
ls -al /var/opt/lab/example.log
please.

And no other process ever accesses/writes to /var/opt/lab/ and/or /var/opt/lab/example.log???

Since you are creating that directory in your script, it is really very likely that you did something wrong in your script.

Do more troubleshooting, e.g.:

1. add
Code:
set -xv
as the 2nd line of your script (right under the #!/bin/bash).

2. Try saving example.log to another directory, one you do not constantly create/delete.
Would be great if you can explain what does set -xv do in this case.
 
Old 08-13-2020, 10:27 AM   #15
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556
Quote:
Originally Posted by jy824212 View Post
Would be great if you can explain what does set -xv do in this case.
Searching for bash "set -xv" returns the relevant part of the Bash manual, along with plenty of other results which answer this.

 
1 members found this post helpful.
  


Reply

Tags
emmc, file systems, linux kernels



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
Construct a one-line command which turns a file into a rhyming dictionary dasidongxi Linux - General 15 01-30-2009 04:42 PM
LXer: Firefly extension turns Firefox into a file browser LXer Syndicated Linux News 0 03-31-2008 06:30 AM
Copying a single file into each directory of a directory tree mlapl1 Linux - Newbie 2 06-27-2007 10:18 PM
16-bit color turns gray into pink! Lord Estraven Linux - Hardware 4 08-04-2005 11:07 AM
CAPS LOCK strangeness -- "a" turns into "S" nschoena Linux - Software 6 06-04-2004 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:47 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