Results 1 to 6 of 6
I have the following script to count how many files root and another user that I can access. Since I am not running it as root, find outputs errors for ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-03-2005 #1Just Joined!
- Join Date
- Mar 2005
- Posts
- 65
Suppressing error messages in bash
I have the following script to count how many files root and another user that I can access. Since I am not running it as root, find outputs errors for directories it cannot open. How can I supress these error messages so only the 2 lines I need will print.
Code:#!/usr/bin/bash root=`find / -user "root"|wc -l` evlschemm=`find / -user "elschemm"|wc -l` echo "I can access $root files owned by root" echo "I can access $evlschemm files owned by elschemm"
- 04-03-2005 #2Just Joined!
- Join Date
- Mar 2005
- Location
- Northern Ireland
- Posts
- 23
hi;
try running the script with:
the "2 > /dev/null" will pipe Standard Error (stderr) output to /dev/null (which means i'll not appear on the screen). Or try:Code:$ ./myscript 2>/dev/null
to pipe any errors to a file (could be useful to check out for errorsCode:$ ./myscript 2>/tmp/myscript_errs.txt
)
Enjoy!
- 04-04-2005 #3Just Joined!
- Join Date
- Mar 2005
- Posts
- 65
These dont seem to work, maybe they need to be logged in as root? I cant log in as root, well I will keep researching.
Thanks
- 04-04-2005 #4Just Joined!
- Join Date
- Mar 2005
- Location
- Northern Ireland
- Posts
- 23
You're getting error messages from the output of the find command; try adding the "2>/dev/null" stderr suppression inside the script:
Code:root=`find / -user "root" 2>/dev/null | wc -l ` evlschemm=`find / -user "elschemm" 2>/dev/null | wc -l`
- 04-04-2005 #5Just Joined!
- Join Date
- Mar 2005
- Posts
- 65
I was gonna try that to...Worked like a charm,
thanks
- 04-04-2005 #6Just Joined!
- Join Date
- Mar 2005
- Location
- Northern Ireland
- Posts
- 23
Great; glad to help.
I forgot that stderr is written too on a "per-command-basis" ; so that's why you need to use the "2>/dev/null" after every command that could produce output you don't want to see.


Reply With Quote
