LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2015, 01:39 PM   #1
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Rep: Reputation: 26
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
 
Old 11-03-2015, 01:53 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ron7000 View Post
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.
 
2 members found this post helpful.
Old 11-03-2015, 03:14 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
On top of the above, have you bothered to look at the man page for find?
 
2 members found this post helpful.
Old 11-03-2015, 04:33 PM   #4
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Original Poster
Rep: Reputation: 26
if i bothered to look at the man page, i would not have bothered posting here asking about it.
 
Old 11-03-2015, 06:18 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ron7000 View Post
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.
 
3 members found this post helpful.
Old 11-03-2015, 07:33 PM   #6
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Original Poster
Rep: Reputation: 26
thanks

for not helping at all
 
Old 11-03-2015, 07:38 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ron7000 View Post
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.
 
4 members found this post helpful.
Old 11-03-2015, 07:56 PM   #8
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Original Poster
Rep: Reputation: 26
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
 
Old 11-03-2015, 11:40 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
 
4 members found this post helpful.
Old 11-04-2015, 01:08 AM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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 .
 
2 members found this post helpful.
Old 11-04-2015, 05:35 AM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by ron7000 View Post
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.
 
3 members found this post helpful.
Old 11-04-2015, 07:59 AM   #12
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,600

Rep: Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083Reputation: 4083
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
 
1 members found this post helpful.
Old 11-04-2015, 08:51 AM   #13
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
2 members found this post helpful.
Old 11-09-2015, 11:10 PM   #14
ron7000
Member
 
Registered: Nov 2007
Location: CT
Posts: 248

Original Poster
Rep: Reputation: 26
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
 
Old 11-10-2015, 02:06 AM   #15
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by ron7000 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
check if file is empty using awk lokesh.talk Linux - Newbie 3 07-03-2015 02:03 PM
Scripting Help--Check empty string condition (not null, but empty!) sungchoiok Linux - Newbie 4 01-01-2012 03:46 PM
[SOLVED] Bash shell script to check the if empty files are being created & start the process hussa1n Linux - General 8 06-29-2010 05:49 PM
How can I make my script check to see if a file is empty? spiffytech Linux - Software 6 01-01-2006 09:35 AM
How can I check wether a file is empty in Linux by using shell script programming ??? Bassam Linux - General 2 02-26-2004 01:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:13 PM.

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