Linux / UNIX Tech Support Forum
This is a discussion on new scripting problem, cat | foreach within the Shell scripting forums, part of the Development/Scripting category; I've found another way to list my dirs and wants to check each dir with the du -khs command. I ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I've found another way to list my dirs and wants to check each dir with the du -khs command.
I have all the directories in a file and wants to read the file and the perform the task for each of the dirs in it. the file consists of rows with dir names followed by / can I cat the file in my script and the perform a foreach loop on them? any suggestions? The output should be one logfile for each of the dirs |
| Sponsored Links | ||
|
|
|
||||
|
Since you have not specified sample input file; I’m going to assume that your file is as follows:
input.txt Code:
/tmp /home/vivek /home/foo /home/bar /etc Code:
#!/bin/bash INPUT="input.txt" LOG="/tmp/log.txt" >$LOG #init log file for f in $(cat $INPUT); do du -ksh $f >>$LOG; done echo "See log file $LOG"
__________________
Vivek Gite Linux Evangelist |
|
|||
|
I've tried some different syntaxes and managed to perform the task like this:
Code:
for i in $(ls -p); do du -khs echo $i; echo $i; done > temp1 cat temp1 | grep ^[0-9] | grep /$ > temp2 Code:
5.6M bin/ 6.7M boot/ 168K dev/ 60M etc/ 597M home/ 8.0K initrd/ 89M lib/ 16K lost+found/ 16K media/ 8.0K misc/ 8.0K mnt/ 8.0K opt/ 899M proc/ 143M root/ 16M sbin/ 0 selinux/ 8.0K srv/ 0 sys/ 576K tmp/ 2.4G usr/ 138M var/ Code:
du: cannot access `echo': No such file or directory the next problem is that i want to specify a directory to go further down in and perform the same task, lets say i want to check the content of the home/ directories, how can i do this? My home directory catalogue structure is like this.. Code:
home/
group1/
user/
user1/
user2/
group2/
user/
user1/
user2/
can you give me som hints? |
|
||||
|
Quote:
Code:
LIST= $(find /home -type d) Code:
for d in $LIST; do du -ksh $d>>/tmp/list.txt; done Code:
less /tmp/list.txt
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Thanks a lot!
I will mix a bit with it and see if i can get it to work smoothly, it seams realy nice! I will write again when it is finnished or when I get stuck again! |
|
|||
|
i just cant get it to work the way i want..
this is what it looks like at the moment Code:
home/
group1
backup
users///
group2
backup
users///
I happy that I went to the hairdresser the other day, otherwise I would be tearing my hair of! |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl scripting | pansarevai | Coding in General | 2 | 17-03-2008 05:34 PM |
| new to scripting | poone1 | Shell scripting | 0 | 15-01-2008 01:19 AM |
| need help on shell scripting | rahul_sayz | Shell scripting | 1 | 08-12-2007 10:37 AM |
| Books on Shell-Scripting | shankar100 | Shell scripting | 3 | 16-02-2007 01:19 PM |
| scripting | ganes | Shell scripting | 2 | 06-09-2005 12:04 PM |