Do i miss counter or what


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Do i miss counter or what
# 1  
Old 05-23-2014
Do i miss counter or what

hello
this script should show all users and space they used without problem :

Code:
ls /home >> /root/users.txt
cat /root/users.txt | while read line; do
space=`du -s /home/$line`
echo "$line space is $space"
shift
done

but when i remove pipe ,script run without any output:

Code:
ls /home >> /root/users.txt
mama=`cat /root/users.txt`
while read $mama; do
space=`du -s /home/$mama`
echo "$mama space is $space"
done

# 2  
Old 05-23-2014
Quote:
Originally Posted by nimafire
hello
this script should show all users and space they used without problem :

Code:
ls /home >> /root/users.txt
cat /root/users.txt | while read line; do
space=`du -s /home/$line`
echo "$line space is $space"
shift
done

but when i remove pipe ,script run without any output:

Code:
ls /home >> /root/users.txt
mama=`cat /root/users.txt`
while read $mama; do
space=`du -s /home/$mama`
echo "$mama space is $space"
done

try this way you will come to know, in second code you are reading nothing so no o/p

Code:
while read line; do
     echo $line
done < "Your_Input_File"

# 3  
Old 05-23-2014
Code:
mama=`cat /root/users.txt`
while read $mama; do

var mama execute cat and read txt file so the input of mama is users.txt
then while command read this file,
can you explain me why nothing so no o/p ?
# 4  
Old 05-23-2014
Have a compare:
Code:
users=$(ls /home --hide=lost+found)	# This sets all content but 'lost+found' into the list: users
for usr in $users;do			# For each entry (named: usr) in list 'users', do ....
	space=$(du -hsx /home/$usr)	# higly recomend 'x' if you mount other filesystems inside user dirs, 'h' makes it more 'readable'
	echo "$usr space is $space"
done


Code:
ls /home --hide=lost+found > /root/users.txt	# Write all content but 'lost+found' into the file: /root/users.txt, using 
while read mama; do				# For each line (named: mama), do ....
	space=`du -s /home/$mama`
	echo "$mama space is $space"
done < /root/users.txt				# while reading from file

hth

Last edited by sea; 05-23-2014 at 04:51 PM..
# 5  
Old 05-23-2014
Quote:
Originally Posted by nimafire
Code:
mama=`cat /root/users.txt`
while read $mama; do

var mama execute cat and read txt file so the input of mama is users.txt
then while command read this file,
can you explain me why nothing so no o/p ?
Imagine that /root/users.txt contains:
Code:
andy
bob
celia
denise

After executing the command mama=`cat /root/users.txt`, the command:
Code:
while read $mama; do
space=`du -s /home/$mama`
echo "$mama space is $space"
done

will be expanded by the shell to:
Code:
while read andy bob celia denise; do
space=`du -s /home/andy
bob
celia
denise`
echo "andy
bob
celia
denise space is $space"
done

which will read lines of text from standard input and assign the first word found on each line to the variable andy, the second word found on each line to the variable bob, the third word found on each line to the variable celia, and the remaining words on each line to the variable denise. I assume that rather than producing no output, it is actually sitting there waiting for you to type in a line in response to the read command.

I hope this explains what you were doing wrong.

Others have already shown you how to fix it.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Solaris 10 boot problem - ERROR: Last Trap: Fast Data Access MMU Miss

Hello, We have a T5140 server with Solaris 10 and its suddenly throwing "segmentation core" when I login into the server and not showing any output for commands like df, mount etc. so I had to reboot the server to fix this issue. Please note that there's no boot disk mirroring. But... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. Shell Programming and Scripting

Counter

if ;then echo "mrnet greater 5000" gzip /var/log/mrnet.log mv /var/log/mrnet.log.gz /var/log/mrnet.log.1.gz if ];then i=1 let i++ mv /var/log/mrnet.log.1.gz /var/log/vieux-logs/mrnet.log.$i.gz else echo "theres no... (1 Reply)
Discussion started by: Froob
1 Replies

3. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

4. Ubuntu

fast data access mmu miss

hello, before i have install solaris 9, is good. I would like to install Ubuntu 10.04 on a Sun Blade 150 blade. I create cdrom iso burning with a 10x was open I made a boot ok: boot cdrom I get the following error: fast data access mmu miss i do probe-ide all reset-all always ... (2 Replies)
Discussion started by: philo_71
2 Replies

5. Shell Programming and Scripting

counter

Hi, I need some help. Shell script counter. i need to add condition to check if counter is more than 10 and longer than 3 hours? it runs every 5 mins. it only check count and send email right now. it runs in cron as below gregcount.ksh gregdb 10 > /tmp/gregcount.out 2> /tmp/gregcount.err ... (1 Reply)
Discussion started by: pega
1 Replies

6. AIX

Miss filesets

Hello everyone I updated a partition from TL06 to TL09, everything looks ok. I check the errpt comand, lppchk -v and both are fine. But when I type this command I got this $ instfix -i |grep ML All filesets for 5300-02_AIX_ML were found. All filesets for 5.3.0.0_AIX_ML were... (3 Replies)
Discussion started by: lo-lp-kl
3 Replies

7. UNIX for Dummies Questions & Answers

Use pipes but miss a action

please delete and see other post. Hi, Im using awk to go through every line, but i have to use it twice as the first awk finds all the lines with a number in one field and the pipes it to wc, and the second does the same as the first but it has a extra pipe into sort and uniq that finds all... (2 Replies)
Discussion started by: fredted40x
2 Replies

8. Solaris

Fast Data Access MMU Miss

Hi All , I am unable to reinstall the OS on my Ultra Sparc 10. After the 1st CD is loaded when it goes for reboot its goes to ok prompt an its unable to boot. What could be reason for this behavior? while loading the OS its seems fine but unable to boot!! Then i tried changing the... (2 Replies)
Discussion started by: kumarmani
2 Replies

9. Shell Programming and Scripting

During deleting just miss some folders

There is directory test: > ls -rtl total 12 drwxr-xr-x 2 root sys 4096 Aug 17 09:57 test2 -rw-r--r-- 1 user1 group1 16 Aug 17 10:00 test -rw-r--r-- 1 user1 group1 16 Aug 17 10:00 test1 -rw-r--r-- 1 user1 group1 16 Aug 17 10:01 test12 -rw-r--r-- 1 user1 group1 16 Aug 17 10:01 test13 ... (5 Replies)
Discussion started by: user_junior
5 Replies
Login or Register to Ask a Question