LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   script help - check for empty file (https://www.linuxquestions.org/questions/programming-9/script-help-check-for-empty-file-4175557893/)

ron7000 11-03-2015 01:39 PM

script help - check for empty file
 
I'm using the find command to check for certain things, and exporting it to a text file.
what i would like to do from within a script, check that file and if it's empty then print success or no problem found. But if there is any thing returned from the find command then echo "hey problem, look in this file".

Code:


# find all files with no owner
find / -nouser > no_owner.txt

# if find command returns nothing, or the file no_owner.txt is empty then
#    print no problem
# else
#    print Files with no owner found!  see no_owner.txt
# endif

thanks

TB0ne 11-03-2015 01:53 PM

Quote:

Originally Posted by ron7000 (Post 5444193)
I'm using the find command to check for certain things, and exporting it to a text file.
what i would like to do from within a script, check that file and if it's empty then print success or no problem found. But if there is any thing returned from the find command then echo "hey problem, look in this file".
Code:

# find all files with no owner
find / -nouser > no_owner.txt

# if find command returns nothing, or the file no_owner.txt is empty then
#    print no problem
# else
#    print Files with no owner found!  see no_owner.txt
# endif


Ok, so can you post what you've written/tried on your own? We're happy to help with a problem, but we're not going to write it for you...you've posted a single find command, with a list of things you'd like to do.

There are MANY easily-found scripting tutorials...along with over 365,000 hits for "bash script to find empty files" in Google, which point you to examples.

grail 11-03-2015 03:14 PM

On top of the above, have you bothered to look at the man page for find?

ron7000 11-03-2015 04:33 PM

if i bothered to look at the man page, i would not have bothered posting here asking about it.

TB0ne 11-03-2015 06:18 PM

Quote:

Originally Posted by ron7000 (Post 5444248)
if i bothered to look at the man page, i would not have bothered posting here asking about it.

And if you bothered reading the Question Guidelines, you'd see you should have. We aren't going to give you handouts....if you can't be bothered, neither can we.

ron7000 11-03-2015 07:33 PM

thanks

for not helping at all

TB0ne 11-03-2015 07:38 PM

Quote:

Originally Posted by ron7000 (Post 5444314)
thanks for not helping at all

"Help" is YOU doing work too. You're asking for a handout, and seem proud of it too. If you're too lazy to even read a man page, then hire someone to do your work for you and pay them.

ron7000 11-03-2015 07:56 PM

http://www.linuxquestions.org/questi...ommand-726352/

why don't you go post in that thread, tell the guy asking for help to go search the web instead.

this is just what i want to do at 9pm at night is scour the web for correct syntax for using find and bash syntax

you should just close this whole program forum

grail 11-03-2015 11:40 PM

So let me get this straight:

1. You have posted here 247 times (so not new)

2. Above would imply you know how this site works and what sort of things people will come back with

3. You have advised how lazy you are because in your own words :- "if i bothered to look at the man page, i would not have bothered posting here asking about it."

4. Instead of looking at the man page, which I suggested being that you are supposedly an experienced user based on number of posts, you would rather search the forum to point out someone else's post from 6 years ago

5. Hard to tell if the OP in post you have cited had many posts by the time they asked the question, but in answer to yours, yes I would have asked if they had read the man page first, if they say yes then I would point out the prune option and if not (or "I can't be bothered") I would suggest they do before getting help

6. gee 9pm and here i was up all night and answered your post at 5am my time, not sure how this has any bearing on the question

7. closing the forum would only disadvantage those users who actually want help

John VV 11-04-2015 01:08 AM

Quote:


for not helping at all
i am not currently a professor in Astronomy / Astrophysics
-- was on that career path

we HELP by pointing you in the right DIRECTION !

and YES , a bunch of us DO come off as thin skinned professors with a student in our office that has NOT done the work .

Habitual 11-04-2015 05:35 AM

Quote:

Originally Posted by ron7000 (Post 5444314)
thanks

for not helping at all

I'd thank you not to waste your time or ours by learning something here.
We are not here to spoon-feed you.
This is not Burger King. You don't get it your way.

Show some maturity.

jeremy 11-04-2015 07:59 AM

ron7000,

The behavior you're exhibiting and language you're using in this thread isn't acceptable here at LQ. You may want to read http://www.linuxquestions.org/questi...#faq_lqwelcome and the LQ Rules again if you're interested in participating here moving forward.

--jeremy

rtmistler 11-04-2015 08:51 AM

BASH File Test Operators

Have a look at the -s option.

Code up a test using that. If you have problems, then post your code and a clear description of your problem as follow-up.

I'm hoping that you don't wait till the last minute and get very frustrated for all things you work on. And if you regularly do work at 9 PM, then complaining about putting in effort is the last thing you wish to do at that time is rather non-charitable.

Note also that having the forum root point out your bad behavior is embarrassing. Or should be. Instead of getting angrier, please learn from it. I'm likely much older than you and I still feel I learn from people.

ron7000 11-09-2015 11:10 PM

all i needed was some basic code,
in fact all it amounted to was the if then fi syntax using an -s command.
if someone posted that code... then someone said hey that's not bad but consider coding it this way and posted some code,

is this not a programming forum?

it would have helped me.
but no, everyone on their high horse like we're in a classroom tells me to look it up on the web and do the work myself.

Quote:

This is not Burger King. You don't get it your way.

Show some maturity.
my response was frustration. I was going to respond the next day but i would have tested your profanity filter.

here's my mature response, you guys have a nice life.

jeremy, you just a lost a member.
you can delete my account here, this site is not helping me anymore.
feel free to delete anything i have ever posted here, especially if it contained code.


btw here's now you help:
https://forums.suse.com/showthread.p...g-diff-command

HMW 11-10-2015 02:06 AM

Quote:

Originally Posted by ron7000 (Post 5447319)
everyone on their high horse like we're in a classroom tells me to look it up on the web and do the work myself.

And that pretty much nails it. You were not interested in doing the work. We, on the other hand were happy to help, but not doing the work for you:
Quote:

Originally Posted by TB0ne
Ok, so can you post what you've written/tried on your own? We're happy to help with a problem, but we're not going to write it for you

You appareantly feel this equals sitting on a ”high horse”, I call it helping someone to help themself.

Best regards,
HMW


All times are GMT -5. The time now is 11:50 AM.