09-26-2008
look into the find command.
man find,,, maybe you can hack some of this script,,,,,, it does not do what you want,, but i think parts of it does-------------------------- look down for the line with "find"
#!/bin/ksh
#
# $0 [-u userID] dir
#
if [[ $setx = "true" ]];then set -x;fi
U_f=false;
for i
do case $1 in
-u*) shift
U_f=true
U=${1};;
-h*) more<<*eof
------------------------------------------------------------------------------------
aha2231
Thu Aug 14 13:59:05 PDT 2008
This script will recursively report out if a file is on tape or if it is on disk
based on ls -s = 256
Usage: $0 [-u $USER ] directory
-u $USER will return only those files owned by $USER
directory requested is $1, or default to current directory
Ex: $0
$0 .
$0 dir
$0 -u $USER dir
------------------------------------------------------------------------------------
*eof
exit;;
-*) echo "\007illegal $0 option $1\007"
$0 -h
exit;;
*) break;;
esac
shift
done
if ${U_f} true; then
U="-user ${U}"
else
U=""
fi
echo USER $USER
echo NODE `hostname`
echo START `date`
dir=${1:-`pwd`}
find ${dir} ${U} -type f -ls | awk ' {
f1="ON %-4s %12.2f %-3s %-7s %-7s %5s %2s %-15s %1s"
flag=$2
s=$7
f=$11
u=$5
month=$8
day=$9
time=$10
group=$6
if(flag=="256" && s/1024 > 256 ) {
q="TAPE"
t[(substr($3,1,1))]++;tsum=tsum+$7
}
else {
q="DISK"
d[(substr($3,1,1))]++;dsum=dsum+$7
}
out1 = sprintf(f1, q, s/1024, "kb", u, group, month, day, time, f)
print out1
}
END{
print tsum/1024/1024/1024 " Gigabytes, and " t["-"] " files are ON TAPE"
print dsum/1024/1024/1024 " Gigabytes, and " d["-"] " files are ON DISK"
}'
exit
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Please help. Here is my problem. I have 9000 lines in file a and 500,000 lines in file b. For each line in file a I need to search file b and remove that line. I am currently using the grep -v command and loading the output into a new file. However, because of the size of file b this takes an... (4 Replies)
Discussion started by: mjs3221
4 Replies
2. Shell Programming and Scripting
Hi,
I have a file which computes fields number and some column produced "nan"
I would like to convert the "nan" value to 0 basically.
q=`echo $i $j |awk '{printf("%f",($2/($1+$2)))}'
The above is the command which I use for computation. However, I would
like to check if $1 and $2 is 0, it... (1 Reply)
Discussion started by: ahjiefreak
1 Replies
3. UNIX for Dummies Questions & Answers
Hi all,
Would like to know how I could search for a string 'xyz' but have the output show the line plus the line above and/or below all lines found.
eg. search for xyz from file containing:
abc
12345
asdf xyz asdfds
wwwww
kjkjkj
ppppp
kkkxyz
eeee
zzzzz
and the output to... (2 Replies)
Discussion started by: sammac
2 Replies
4. Shell Programming and Scripting
hello,
I have to write a script to run the other script inside it.So iam planning to write like this?
first check the perimissions of the file.
Alogorthim
----------
if(!filepermissions == execute)
then
echo" Permissions denined"
else
execute the script.
file name is : load_mf.sh... (1 Reply)
Discussion started by: rajkumar_g
1 Replies
5. Shell Programming and Scripting
Hi,
i have to insert the content of source.txt into the searched pattern of the file second.txt.
$cat source.txt
One
Two
Three
.
.
$cat second.txt
This is second file
pattern match start here
pattern match end here
end of the file
so the result will be like this (4 Replies)
Discussion started by: posix
4 Replies
6. Programming
Hi,
For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755.
Am able to check this using the statement:
"if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):"
But the problem here... (0 Replies)
Discussion started by: arjun_arippa
0 Replies
7. Shell Programming and Scripting
Hi,
For a particular set of files, am trying to check if they are writable. i.e., checking whether they are having permissions greater than 755.
Am able to check this using the statement:
"if (os.path.isfile(FILE_PATH) and (os.stat(FILE_PATH).st_mode & 0777) == 0777):"
But the problem... (1 Reply)
Discussion started by: arjun_arippa
1 Replies
8. UNIX for Dummies Questions & Answers
Is there a way to check when the permissions for the file got changed in AIX
IS there some file which logs all these details?
Best regards,
Vishal (4 Replies)
Discussion started by: Vishal_dba
4 Replies
9. Shell Programming and Scripting
Hello All,
While searching for the question, I found some answers but my implementation is not giving expected output.
I have two files; one is sourcefile, other is named template.
What I want to do is to search each line in template, when found all columns, cut the matching line from source... (4 Replies)
Discussion started by: baris35
4 Replies
10. Shell Programming and Scripting
Hello,
I would like to know if it's a good practice to check the file permissions of the contents of a directory before moving them. For example:
mv -- "$directory"/* "$directory"/.* "$directory"/..?* "$destination"The variables $directory and $destination contain the path to an existing... (6 Replies)
Discussion started by: Cacializ
6 Replies
LEARN ABOUT NETBSD
zfgrep
ZGREP(1) BSD General Commands Manual ZGREP(1)
NAME
zgrep, zegrep, zfgrep -- print lines matching a pattern in gzip-compressed files
SYNOPSIS
zgrep [grep-flags] [--] pattern [files ...]
zegrep [grep-flags] [--] pattern [file ...]
zfgrep [grep-flags] [--] pattern [file ...]
DESCRIPTION
zgrep runs grep(1) on files or stdin, if no files argument is given, after decompressing them with zcat(1).
The grep-flags and pattern arguments are passed on to grep(1). If an -e flag is found in the grep-flags, zgrep will not look for a pattern
argument.
zegrep calls egrep(1), while zfgrep calls fgrep(1).
EXIT STATUS
In case of missing arguments or missing pattern, 1 will be returned, otherwise 0.
SEE ALSO
egrep(1), fgrep(1), grep(1), gzip(1), zcat(1)
AUTHORS
Thomas Klausner <wiz@NetBSD.org>
BSD
December 28, 2003 BSD