Sponsored Content
Full Discussion: a find script
Top Forums Shell Programming and Scripting a find script Post 81387 by blowtorch on Friday 19th of August 2005 02:30:12 AM
Old 08-19-2005
a find script

I wrote this find script for all those questions about 'files created in the last three hours' and 'files created more than 2 minutes ago'. This script *will* recurse into subdirectories.
As always, please suggest/make changes as you see fit.

Code:
#!/usr/bin/ksh
#set -x                 # unhash for debugging

print_help(){
        echo "Usage: find.sh <num><h|m> dir_to_search_in <older|newer>"
        echo "example:
        find.sh 3m /tmp newer
this will search in /tmp for files created in the last 3 minutes.
        find.sh 3h /tmp older
this will search in /tmp for files older than 3 hours."
}

PERLDIR=/opt/perl/bin # you can specify the path of your perl binary here
if [ $# -ne 3 ]; then
        print_help
        exit -2
fi
ARG1=$1
ARG2=$2
ARG3=$3

case "$ARG3" in
        "newer") new_val="-newer";;
        "older") new_val="! -newer";;
        *) print_help; exit -2;;
esac
unit=`$PERLDIR/perl -w -e 'print chop $ARGV[0]' $ARG1`
diff=`$PERLDIR/perl -w -e 'print substr $ARGV[0],0,-1' $ARG1`
case $unit in
        h) mult=3600;;
        m) mult=60;;
        *) print_help; echo "PLEASE NOTE: Only hour or minute granularity supported. For coarser stuff, use regular find. Finer granularity not yet supported."; exit -1;;
esac
diff_sec=$(($diff*$mult))
then_time=`$PERLDIR/perl -w -e '@mytime=localtime (time - $ARGV[0]); printf "%d%.2d%.2d%.2d%.2d", $mytime[5]+1900,$mytime[4]+1,$mytime[3],$mytime[2],$mytime[1];
' $diff_sec`

touch -m ${then_time} $ARG2/file_for_find
find $ARG2 -type f $new_val $ARG2/file_for_find
rm $ARG2/file_for_find
exit

--EDIT--
This has been tested on a HPUX 11.11 system. All utilities are HPUX standard.
--EDIT--

Last edited by blowtorch; 08-19-2005 at 03:46 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find Script file location inside script

I have to find out the file system location of the script file inside script. for example a script "abc.sh" placed anywhere in the file system when executed shold tell by itself the location of it. example #pwd / #./abc this is / #cd /root #./abc this is /root #cd / #/root/abc this... (10 Replies)
Discussion started by: asami
10 Replies

2. Shell Programming and Scripting

Getting a script to find another script via lookup service

Hi, I'm trying to write a basic script which will measure throughput at a node on a network, and pass the results on to a manager script (running on another node on the same network). I presume that I need to use some sort of naming service, so that the manager can publish its location. From what I... (2 Replies)
Discussion started by: zeppelin147
2 Replies

3. Shell Programming and Scripting

Need help in a find script

i have a below script that will give me the filename along with the their size if the file size is more than 1 GB for j in `find /ednadtu3/u01/pipe -type f -size +1048576` do du -g $j done -------------------------------------------------------------------------- the above script is... (3 Replies)
Discussion started by: ali560045
3 Replies

4. Shell Programming and Scripting

Help with find in a script

Hi, I am trying to find files in a directory. I am passing a part of the file name as parameter 3 in my script. but my find command doesn't see to take it correctly find $IRC_PATH -type f -name `${3}`*.gz -print Here $3 is part of file name I am passing as parameter. My files will look... (11 Replies)
Discussion started by: dsravan
11 Replies

5. Shell Programming and Scripting

Find script

Hello, as I'm doing my first steps in Linux I'm trying to create bash file that will search file\s in folders by using the Find command. can u help me with the script? it should be : myfind.sh thanx! (2 Replies)
Discussion started by: SimonBASH
2 Replies

6. Shell Programming and Scripting

Need help to find script

Hello, I have a log file which is called datafile.info. This file contains data from a script but I can't find the script. I have tried to grep the file name but I am only getting the output files back. I have also tried find but no luck again. Is there a way to find the script... (2 Replies)
Discussion started by: INHF
2 Replies

7. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

8. Shell Programming and Scripting

How to find a script?

I need to find the script named jip.sh how can i search it ? (13 Replies)
Discussion started by: rafa_fed2
13 Replies

9. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

10. Shell Programming and Scripting

Help with better find script

hi everyone i tried to write my first script on unix solaris the target is to find every file had size above 200M and save it to log file with size and path i can do this but i still don't like it #!/bin/bash find / type f -size +200M -ls | log.txt is there better way to do this !!... (3 Replies)
Discussion started by: mondo32
3 Replies
EXPR(1) 							   User Commands							   EXPR(1)

NAME
expr - evaluate expressions SYNOPSIS
expr EXPRESSION expr OPTION DESCRIPTION
--help display this help and exit --version output version information and exit Print the value of EXPRESSION to standard output. A blank line below separates increasing precedence groups. EXPRESSION may be: ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0 ARG1 < ARG2 ARG1 is less than ARG2 ARG1 <= ARG2 ARG1 is less than or equal to ARG2 ARG1 = ARG2 ARG1 is equal to ARG2 ARG1 != ARG2 ARG1 is unequal to ARG2 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2 ARG1 > ARG2 ARG1 is greater than ARG2 ARG1 + ARG2 arithmetic sum of ARG1 and ARG2 ARG1 - ARG2 arithmetic difference of ARG1 and ARG2 ARG1 * ARG2 arithmetic product of ARG1 and ARG2 ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2 ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2 STRING : REGEXP anchored pattern match of REGEXP in STRING match STRING REGEXP same as STRING : REGEXP substr STRING POS LENGTH substring of STRING, POS counted from 1 index STRING CHARS index in STRING where any CHARS is found, or 0 length STRING length of STRING + TOKEN interpret TOKEN as a string, even if it is a keyword like 'match' or an operator like '/' ( EXPRESSION ) value of EXPRESSION Beware that many operators need to be escaped or quoted for shells. Comparisons are arithmetic if both ARGs are numbers, else lexicograph- ical. Pattern matches return the string matched between ( and ) or null; if ( and ) are not used, they return the number of characters matched or 0. Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION is null or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred. AUTHOR
Written by Mike Parker, James Youngman, and Paul Eggert. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report expr translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
Full documentation at: <http://www.gnu.org/software/coreutils/expr> or available locally via: info '(coreutils) expr invocation' GNU coreutils 8.28 January 2018 EXPR(1)
All times are GMT -4. The time now is 06:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy