Sponsored Content
Full Discussion: Using a loop with cut
Top Forums Shell Programming and Scripting Using a loop with cut Post 302476134 by ninjafish on Wednesday 1st of December 2010 01:04:55 AM
Old 12-01-2010
ok so du -skh /home/* works better than what I was using, but the part of it i'm not understanding is how to implement it into a loop. The two lines I posted were to copy the user names for the system into a text file. Now I need to figure out how to use a loop to go through that text file, cutting out each user name, and displaying the storage use for each user.

If it helps, I can copy and paste the question I am trying to do. I printed a bunch of tutorial things offline to try to learn from.

Code:
Take the following scenario when you are the system administrator to purchase a larger disk drive for your Linux server. You receive a phone call from an angry user, who claims that they are unable to save the files. To solve this problem quickly, you must check which user had taken most of the disk space and then make a decision what to do.  

Display the Device name, used space for each disk in kilo bytes and also the total available disk space in GB with meaningful headings sorted by Capacity. 

Display the usage in kilo bytes sorted in descending order (highest as the first line) for the first 10 users. (Test in Ubantu only as opentech does not allow you to access the other users. Create 3 or 4 users in Ubantu and 4 to 5 files in each user’s directory). 

Ask the user to enter the size of the used space in Kilobytes. List all users whose used space is  more than the size entered by the user as:
Login Name    User Full name		Used space

Login Name is the directory name itself. User Full name can be obtained from /etc/passwd command.

I'v spent a couple days on this already, and it's making me wannna go crazy

Last edited by ninjafish; 12-01-2010 at 12:44 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use loop var i within Cut Command

Hi, In the following bash code rather than cutting at a predefined character I would like to cut at position i (i var from loop). Is this possible? I have tried eval, but either it's not possible or my syntax is wrong. thanks Nick for i in {1..9} do theChar=$(echo... (3 Replies)
Discussion started by: de_la_espada
3 Replies

2. UNIX for Dummies Questions & Answers

Cut not working in a loop

I have a function "MyPrint" that runs great on a file (BaseData.txt) that has one line of data. If i add rows to the text file it's reading the tFile variable becomes a list of every field 2 in the file. To correct this, i tried to call the function from a loop where i read one line at a time and... (4 Replies)
Discussion started by: KME
4 Replies

3. Shell Programming and Scripting

Problem in getting data from a loop using grep and cut

The script is following : for each_rec in <file_name> do count=`cut -c -2 ${each_rec} | grep "45"` echo ${count} if ] then amount=`cut -c 24-35 ${each_rec}` echo ${amount} else echo "failed" fi done And the file looks like below : ... (4 Replies)
Discussion started by: mady135
4 Replies

4. Shell Programming and Scripting

cut -f1 -d"," to a array and loop

############## SOLVE ############# Hi I would like to do something quite simple but i could not figure it out Example file: BAS,Fast ZeroSPEC,Fast ZeroSPEC,Fast Zero,CAD MASTER SWAP BAS,Fast ZeroSPEC,Fast ZeroSPEC,Fast Zero,CHF SWAP GOTTEX BAS,Fast ZeroSPEC,Fast ZeroSPEC,Fast... (10 Replies)
Discussion started by: kykyboss023
10 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Shell Programming and Scripting

UNIX shell script - cut specified line and perform loop

Guys, I have a requirement as below. consider,if i use df command, its getting the below output. file system kbytes used avail %used Mounted on /dev/sample/ 45765 40000 5765 50% / /dev/filesys/ 30000 20000 1000 80% /u .... .... Now i wanted to cut the /u... (11 Replies)
Discussion started by: AraR87
11 Replies

7. Shell Programming and Scripting

Cut command not working in for loop

grep -Fxvf testdata.xls file_GTDA1.xls >file_GTDA.xls SLS_COUNT=`grep 'GTDA_Dly_Sls' file_GTDA.xls |wc -l` PMIX_COUNT=`grep 'GTDA_Dly_Pmix' file_GTDA.xls |wc -l` if ; then var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'` var4="|" for i in $var1... (7 Replies)
Discussion started by: renuk
7 Replies

8. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

9. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies
listusers(1)						      General Commands Manual						      listusers(1)

NAME
listusers - display user login data SYNOPSIS
groups] logins] DESCRIPTION
The command displays data concerning user logins. The output shows the user login and the comment field value (for example, user name, location). The default displays data about all user logins. Options The command supports the following options: Display only users who have groups, as their primary group. Use with the option. Display only users who have groups, as their supplementary group. Use with the option. Display all users belonging to groups, sorted by login. A comma separated list specifies multiple groups. Display the requested logins. A comma separated list specifies multiple logins. Display only users belonging to the specified repository, either for NIS or users. A user login has a UID of 100 or greater. When the and options are combined, a user login is only displayed once, even though the login may belong to multiple specified groups. EXAMPLES
List all user logins. List all user logins in the group and the users removing all duplicates. List all users who have as their primary group. List all users who have as their supplementary group. List only local user logins. List only NIS user logins. FILES
SEE ALSO
passwd(1), logins(1M), group(4), passwd(4). STANDARDS CONFORMANCE
listusers(1)
All times are GMT -4. The time now is 09:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy