"Find " command andshell scripting
hi,
I recently tried to write a shell script that looks in a directory and deletes all files matching a certain pattern which are more than 45 days old.
I used the "find" command. the problem is that the find command recursively searches all the subdirectories present. I NEED TO RESTRICT THIS AND ENSURE THAT THE SEARCH IS RESTRICTED TO THE SPECIFIED DIRECTORY ONLY.
the script is as follows:
for file in `find . -mtime +15 -print`
do
if [ -f $file ]
then
echo "Removing $file that existed more than 15 days."
rm $file
#use mv command to some temp dir for testing
fi
done.
I am on a solaris 5.6 machine and need help that will work on that version. I tried other commands such as locate and glimpse but the ksh does not seem to recognze tham at all. Also there is man page entry for these commands.
In solaris, the find command comes with an option called -depth that restricts the depth of the search but i am not able to work it. The man pages abt this option says:
-depth : Always true; causes descent of the directory
hierarchy to be done so that all entries in a
directory are acted on before the directory
itself. This can be useful when find is used
does anyone know how to work this?
Also, the man page mentions that the depth is determined by an environment variable PATH_MAX. I am not able toset this variable. The man page for that says:
find will be able to descend to arbitrary depths in a file hierarchy and will not fail due to path length limitations (unless a path operand specified by the application exceeds PATH_MAX requirements).
Can someone tell me how to restrict this?
I would appreciate it if you could cc a copy to my mail id :[email protected] as i have a lot of trouble accessing the net
Regards,
Sailesh
hi
i got a way but why dont you break it in to two scripts first script will search for the file path and redirects in to a file and then when its search is end start the removing your file by grep the file path from that file i think its simple
Similar Messages
-
Linux command/shell script to find Memory consumed by JVM in EBS,SOA
Hi All,
Could anyone please let me know the following:
a)Linux command/shell script to find Memory consumed by JVM for every 1 minute frequency interval in EBS R12, SOA suite
b)Percentage of the Heap memory usage by the JVM for every 1 minute frequency interval in EBS R12, SOA suite
Thanks for your time!
Regards,user10088255 wrote:
Hi All,
Could anyone please let me know the following:
a)Linux command/shell script to find Memory consumed by JVM for every 1 minute frequency interval in EBS R12, SOA suite
b)Percentage of the Heap memory usage by the JVM for every 1 minute frequency interval in EBS R12, SOA suite
Thanks for your time!
Regards,Please see these docs.
JVM: Guidelines to setup the Java Virtual Machine in Apps Ebusiness Suite 11i and R12 [ID 362851.1]
Generate JVM heap dump in E-Business suite 11i and R12 [ID 462550.1]
11i: How To Use Jconsole to Monitor JVM with Oracle E-Business Suite 11i [ID 415455.1]
Configuring various JVM tuning parameters for Oracle E-Business suite 11i and R12 [ID 567551.1]
Script to find Apache, Java, Jinitiator, Forms version and JVM details for Oracle E-Business Suite 11i [ID 466890.1]
JVM Memory Monitoring, Tuning, Garbage Collection, Out of Memory, and Heap Dump Analysis For SOA Suite Integration 11g [ID 1358719.1]
How to Perform Memory and Thread Analysis on SOA [ID 1450293.1]
Thanks,
Hussein -
Please Help. compare two excel files. Can't get the find command to work
Hello, I'm new to applescript. I'm trying to write a script to compare column B of one excel file to column B of the another excel file.
I will have to had a repeat loop to proceed down the column but I'm stuck on the find command.
Below is some of the code I have so far. The applescript error message is "Microsoft Excel got an error: The object you are trying to access does not exist. It highlights the find column."
set patientFile to choose file with prompt "Please select the patient Excel file:"
set patientName to name of (info for patientFile)
tell application "Microsoft Excel"
open patientFile
set thepatientFile to workbook patientName
end tell
display dialog "Is your patient SNP data in column B of the " & " " & patientName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put your data in column B" buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
display dialog "Is column E empty? The results of this program will be stored in column E of the" & " " & patientName & " " & "excel file." buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put your data in empty column E" buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
set relativeFile to choose file with prompt "Please select the relative Excel file:"
set relativeName to name of (info for relativeFile)
tell application "Microsoft Excel"
open relativeFile
set therelativeFile to workbook relativeName
end tell
end if
end if
display dialog "Is your relative SNP data in column B of the" & " " & relativeName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put your data in column B" buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
display dialog "Does column C contain the result data you would like copied from" & " " & relativeName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put the data you would like copied in column C." buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
tell application "Microsoft Excel"
activate object workbook patientName
copy value of cell "A1" to cellPatientFile
find (range "B:B" of workbook relativeName) what cellPatientFile
if cellPatientFile is true then
set bold of font object of cellPatientFile to true
end if
end tell
end if
end if
Does any one have any hints towards solving this problem? Thank you for any help.Hi,
taffners wrote:
Thank you everyone for your help. I attached my code. It works now but kinda slow. Does anyone have any hints on making it faster.
Important : when you use the find command, it's preferable to use the properties ( look in and look at).
Example : find searchRange what searchTerm look in values look at whole
Otherwise, it will search according to the criteria of your last find.
Example, if you uncheck 'Find entire cells only', and after that you run the script,
find column 2 what 10.0 --> match 110.0 or 1110.0 or 310.0, .... , because it look at part.
set screen updating to false : Yes it improves the speed.
Here are my tests (no duplicate values in the Excel column ) on old computer (Powermac G5) .
set screen updating to false without any activate object command
2000 rows --> 3.7 minutes, your script : 11.5 minutes
4000 rows --> 7.5 minutes, your script : 23 minutes
8000 rows --> 15 minutes, your script : 46 minutes
But, it's faster to search through a list without using the Excel find command, no need to set the screen updating, You can continue working on the workbook or another workbook, this will not disturb the script.
Tests on my script :
2000 rows --> 4 seconds
4000 rows --> 21 seconds
8000 rows --> 1.3 minutes
17000 rows --> 6 minutes
Here is the script :
main()
display dialog "Done"
on main()
script o
property patientSNP_list : {}
property relativeSNP_list : {}
property resultsList : {}
property copyAnswerList : {}
on findLookAtWhole(value) -- case sensitive
set {low, high} to {1, count my relativeSNP_list}
considering case
repeat while low ≠ high
set mid_ to (low + high) div 2
if value is in items low thru mid_ of my relativeSNP_list then
set high to mid_
else
set low to mid_ + 1
end if
end repeat
end considering
if (item low of my relativeSNP_list is value) then
set end of my resultsList to item low of my copyAnswerList
else
set end of my resultsList to {"no"}
end if
end findLookAtWhole
end script
--opens File1. Names it patientName
set patientFile to choose file with prompt "Please select the patient Excel file:"
set patientName to name of (info for patientFile)
tell application "Microsoft Excel"
open patientFile
set thepatientFile to workbook patientName
set patientSheet to sheet (name of active sheet) of thepatientFile
end tell
--This Dialog assigns where the data is stored for file1
display dialog "What Column is your patient SNP data of the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
set PatientSNPCol to (text returned of the result)
--This Dialog assigns what row your data starts at for file1
display dialog "What row does your patient SNP data start in the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
set patientSNPRow to (text returned of the result)
set patientStartCell to PatientSNPCol & patientSNPRow
--This Dialog assigns the last row of data for file1
display dialog "What row is the last row of you patient SNP data start of the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
set patientLastRow to (text returned of the result)
set patientLastCell to PatientSNPCol & patientLastRow
--This Dialog assigns the location of the data copied from file2
display dialog "What column would you like the results of this program stored in of the" & " " & patientName & " " & "excel file." default answer "" buttons {"submit"} default button 1
set resultsLocation to (text returned of the result)
--opens File2. Names it relativeName
set relativeFile to choose file with prompt "Please select the relative Excel file:"
set relativeName to name of (info for relativeFile)
tell application "Microsoft Excel"
open relativeFile
set therelativeFile to workbook relativeName
set relativeSheet to sheet (name of active sheet) of therelativeFile
end tell
--This dialog assigns the column of data in file2
display dialog "What Column is your relative SNP data of the " & " " & relativeName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
set relativeSNPCol to (text returned of the result)
--This dialog assigns the column of data begining copied to excel file1.
display dialog "What Column contains the data you would like copied to the " & " " & patientName & " " & "excel file in column" & " " & resultsLocation & " " & "?" default answer "" buttons {"submit"} default button 1
set copyAnswer to (text returned of the result)
tell application "Microsoft Excel" -- get values
set o's patientSNP_list to value of range (PatientSNPCol & patientSNPRow & ":" & PatientSNPCol & patientLastRow) of patientSheet
set lastrow to first row index of (last cell of used range of relativeSheet)
set o's relativeSNP_list to value of range (relativeSNPCol & "1:" & relativeSNPCol & lastrow) of relativeSheet
set o's copyAnswerList to value of range (copyAnswer & "1:" & copyAnswer & lastrow) of relativeSheet
end tell
set tc to (count o's relativeSNP_list)
repeat with i from 1 to tc --convert list of lists to one list
set item i of o's relativeSNP_list to item 1 of item i of o's relativeSNP_list
end repeat
set tc to (count o's patientSNP_list)
repeat with i from 1 to tc -- AppleScript find method, not the Excel Find
o's findLookAtWhole(item 1 of (item i of o's patientSNP_list))
end repeat
tell application "Microsoft Excel" -- set values
set value of range (resultsLocation & patientSNPRow & ":" & resultsLocation & patientLastRow) of patientSheet to o's resultsList
end tell
end main
If you have lots of rows and you want it to go faster.
I have another script that uses the power of (/usr/bin/awk and his associative arrays) in a do shell script
17000 rows --> awk : 2 seconds, applescript : 6 seconds, total : 8 seconds
34000 rows --> awk : 3 seconds, applescript : 11 seconds, total : 14 seconds -
About control commands in scripts
hi abapers
can u plz tell about control commands in scripts uses of control commandsHi,
Control Command Purpose:
The purpose of these is to allow control of the output formatting. These commands are not interpreted by the SAPscript editor, but are passed through to the SAPscript Composer for processing. The Composer is the program that converts text from the form displayed in the editor to the form used for printing. This includes, for example, line and page formatting, the replacement of symbols with their current values and the formatting of text according to the paragraph and character formats specified.
The SAPscript control commands are described in the following sections.
<b>Syntax of Control Commands</b>
Explicit Page Break: NEW-PAGE
Preventing Page Breaks: PROTECT
Next Main Window: NEW-WINDOW
Assigning a Value to a Text Symbol: DEFINE
Formatting Date Fields: SET DATE MASK
Formatting Time Fields: SET TIME MASK
Country-Dependent Formatting: SET COUNTRY
Position of the Leading Sign: SET SIGN
Initializing Numbered Paragraphs: RESET
Including Other Texts: INCLUDE
Changing the Style: STYLE
Formatting Addresses: ADDRESS
Setting a Header Text in the Main Window: TOP
Setting a Footer Text in the Main Window: BOTTOM
Conditional Text: IF
Finding a Match: CASE
Calling ABAP Subroutines: PERFORM
Inserting Print Controls: PRINT-CONTROL
Boxes, Lines, Shading: BOX, POSITION, SIZE
Hexadecimal Data: HEX, ENDHEX
Summing a Program Symbol: SUMMING
Br,
Laxmi -
File path from find command and using POSIX
Hi,
I have a find command in do shell script returning output files of the form ./xyz/abc/.../...
instead of the full path.
I am guessing that this is the problem when I use POSIX path of one of those files. Can Applescript understand the "./" or does it need a full Unix path to convert it back?
In that case, how do I ask find command to return the full path?
Thanks in advance!>I am guessing that this is the problem when I use POSIX path of one of those files. Can Applescript understand the "./" or does it need a full Unix path to convert it back?
You're right - AppleScript won't be able to use those paths because AppleScript has no idea of the current directory used by the shell.
The problem is that you're defining '.' a the start point of your search.
For each matching file find will print this start point in front of the relative path, assuming that you know where you're starting from. So the solution is to provide that path as the search start point rather than .
For example, if your current script says:
<pre class=command>cd /some/directory
find . -name "*.mp3"</pre>
You could/should rewrite this as:
<pre class=command>find /some/directory -name "*.mp3"</pre>
in the second case all matches would include the full path including the /some/directory part.
If you can't predict what your search directory will be you can write your find like this:
<pre class=command>find `pwd` -name "*.mp3"</pre>
which will fill in the current directory (via pwd at the time the search is executed and will output full paths that AppleScript can work with. -
Hi Community,
after a file server migration I lost on each folder all Finder labels. With the lsmac utility I can fetch the label color for each object and with the setlabel utility I can set a label color for objects. Both utilities come with the osxutil suite.
Okay so far so good, the solution is based in this two utilities but how can I combine this two commands in a script which read out the label colors of each folder on the source file server and set the right label color of each folder on the target file server. Both servers are mounted via AFP on a Mac workstation.
The following (test) command reads only a few folders, I would expect that the find command should run recursively but it doesn't:
$ find / -type d -print0 | xargs -0 lsmac -L
Orange ------ 93 items - Applications/
None I----- 37 items - bin/
None I----- 0 items - cores/
FSPathMakeRef(): Error -36 returned when getting file reference from //dev
None ------ 14 items - Developer/
The following command run like the **** but print out mostly garbage:
$ find / -type d -print0 -exec lsmac -L {} ;
Okay, now I've already problems to determine the right label color of each folder. I'm far away from setting a label color. Help would be very appreciated in this job.
Thx & Bye TomI do NOT know the syntax of the lsmac nor the setlabel commands, so this is just an untested template.
#!/usr/bin/env bash
find / -type d | while read file
do
color=$(lsmac "$file")
[[ "$color" = None * ]] && continue
[[ "$color" = *: Error* ]] && continue
(set -x
setlabel "${color%% *}" "/Volumes/REMOTEVOLUMENAME/$file"
done -
Unix find command...
My problem exists with the behavior on the unix find command, or my lack of understanding of it.
For example, I work for a graphics company and we have a constant folder structure like this:
*12345 Apple - Poster*
~....~01_Layouts
~....~02_Images
~....~03_Fonts
~....~04ClientOriginals
~........~01.28.08_14:46
~........~03.07.08_15.03
~........~03.10.08_17.22
When we receive files from a customer, the CSR creates a folder inside 04ClientOriginals following a format like 03.06.08_10.15, and copies the files/folders from customer supplied media into them.
I have set up a launchd script that finds all of the date/time stamped folders inside of 04ClientOriginals that have not been modified within the past month and stuff them with the Stuffit command line utility. I do that with this command:
find . -type d –mtime +30 -ipath #/04ClientOriginals/# -exec /usr/local/bin/stuff -f sit5 -m 2 -o -D {} \;
This command works fine except in those cases where there are folders over 30 days old inside of a parent directory that is not 30 days old yet. I only want the find to descend to one level below 04ClientOriginals, and no further.
I thought by adding an extra "/" at the end of the path #/04ClientOriginals/#/ instead of #/04ClientOriginals/# would keep it from descending further down, but when I try this the search returns no results. Also, I can’t use -maxdepth in my find arguments because the depth of 04ClientOriginals is not always constant.
Any help would be greatly appreciated.
Thanks.
Edit: Due to the lack of decent markup tools for formatting code on the Apple Discussion Board, the wildcards in my file paths have been substituted with a "#". Kind of ridiculous for a unix discussion board to not have code highlighting capability.
Message was edited by: Guriboyetresoft wrote:
I don't know if these will work or not. Regular expressions are powerful, but tricky. Plus, there are a few different, but similar, varieties. Also, I don't know if the find within a find syntax will work. This might be something that is better suited to Perl. You would then have much more control over what you are doing.
Running this find command finds exactly what I'm looking for:
find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 ;
I hope I'm wrong, but can't you call -exec only once? As a test I ran this:
find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 -exec ls -l {} ;
If I invoke -exec a second time, I get this error:
find: -exec: no terminating ";" or "+"
find: -exec: no terminating ";" or "+"
find: -exec: no terminating ";" or "+"
I've searched high and low and I cannot find an example of the find command calling -exec more than once.
My regex skills are pretty weak, so I'll only tread those waters if I have to. -
Any good Power Shell command or script to see connected users in real time for Lync 2013
Are there any good Power Shell commands or scripts that can tell you how many users are connected to a pool in real time so you can evaluate the current load. I have 3 FE servers in a single pool. We just started deploying the lync client to the users and
were curious as to how many are actually connected. I saw a number of home made scripts but really didn't care for any of them. I just want to find out how many users that are actually connected to the pool at a particular moment so we can see how many users
are really using the product.Have you looked at Pat Richard's get-csconnections script?: http://www.ehloworld.com/269
Please mark posts as answers/helpful if it answers your question.
Blog
Lync Validator - Used to assist in the validation and documentation of Lync Server 2013. -
A Unix question: find command
Hi all,
Sorry for posting a Unix question here.
In the following directory I have:
/opt/SonicSoftware/SonicMQ/samples/TopicPubSub/DurableChat>ls
DurableChat.class DurableChat.java Readme.txt
However, if I try:
/opt/SonicSoftware>find -iname DurableChat.class
The path can not be found, it just gives me the prompt back; I don't know what the reason is. Any idea?I'm just wondering can the symbolic link be the
reason that class file can not be found (I guess, not
though, b/c other classes can be found):What do you mean "not found"?
Do you mean why the find command isn't finding it? Yes, that's why. But now that you know, you can use -follow.
Or do you mean the VM is unable to find the class at runtime? I'm almost certain the classloader can follow symbolic links in the classpath, so I don't think that's the problem.
>
/opt/SonicSoftware/SonicMQ/samples/TopicPubSub/Chat>..
/../SonicMQ.sh DurableChat -u AlwaysUp
Exception in thread "main"
java.lang.NoClassDefFoundError: DurableChat
Should I change the path that it won't be symbolic
anymore?Try it and see if it fixes it. I'd be surprised, but you never know. If making it not a link fixes it, then maybe that's what you have to do. If it doesn't fix it, then you know you have to look somewhere else. -
Transaction to find ecatt test script
transaction to find ecatt test script and the table which stores ecatt test script
transaction to find function group and the table which stores function group
transaction to find general text and the table which stores general text
where i should be able to change the devlopment classHi Avinash,
For ecatts check development class/package SECATT_DDIC and transaction SECATT.
For general text transaction is SO10 and tables are STXH and STXL.
For Object Naviagtor SE80 you can change development class.
For function groups check ENLFDIR table.
All transaction codes are stored in TSTC and TSTCT tables
Thanks
Lakshman -
How to find out the script name used in driver program
Hi Folks ,
I want to find out the Scripts(print program) used in my driver pogram .
How is it possible any Tcode availble for this ?
Thanks ,
Jaga.DHi Jagadish,
Go to transaction SE38 and open the program RSNAST00. There search for the subroutine TNAPR_LESEN.
Set a break point at that subroutine and leave. When printing the data from a transaction to a script or form (Like VA01 or VL02N), debugger is started when the processing reaches the subroutine in RSNAST00. There double click on the field TNAPR-FONAM. continue step-by-step execution. The field will display the name of the script or form that is currently being used.
Another way to do this is to go to transaction NACE and check the transaction for which you want to find out the script. There you will find the script and print program that have been set for a particular transaction. -
Different parameters for different sheets- Command Line Script
Hi,
I am using command line script to run my discoverer report.
I have 5 sheets in the workbook out of which, 2 has a PeriodID parameter, and the other 3 sheets does not have parameters.
Is it possible to execute this scenario.
This is the script i use:
string8 = "C:\oracle\BIToolsHome_1\bin\dis51usr.exe /connect uname/pwd@instance /apps_gwyuid APPLSYSPUB/PUB /apps_fndnam APPS /apps_user /apps_responsibility Resp_Name /opendb workbook /sheet sheet1 /sheet sheet2 /sheet sheet3 /parameter PeriodID 2008004 /sheet sheet4 /parameter PeriodID 2008004 /sheet sheet5 /export XLS file_name /batch"
Your inputs are highly appreciated.
Thanks.Hi
No, you cannot do this. You have to supply the parameters to each worksheet separately, even though different worksheets may use the same parameter(s).
Best wishes
Michael -
Command Line Scripts in File Adapter
Hi,
In the file adapter, does the command line script support "PERL" Scripts.
thanks.
KrishnanYES It will support.
For clarification check below one.
/people/sameer.shadab/blog/2005/09/21/executing-unix-shell-script-using-operating-system-command-in-xi
FTP channel - not processing files, coz one of the files is wrong, -
I can't find the MATLAB script node in labview
We are using a MAC G4 with OS 9. We also have labview 5.1. I have looked under Mathematic>>Fomula in the tools palette and I cannot find the MATLAB script node.
Is there an extra download that I need to get this MATLAB script node?The HIQ and MATLAB script nodes are only available in the full and professional development systems. If you have one of these versions, these nodes should be under the Mathematics>>Formula palette.
If you have the base package of LabVIEW, you will not have access to these script nodes. Details about which options are included in which development packages can be found at:
http://www.ni.com/labview/devchart.htm -
Find Command in iCal doesn't work
I have tried to use the Find Command in iCal. It doesn't work either from the Edit pull down command nor the keyboard command. Please try this in your setup and tell me whether it works?
I have an Intel Mac Mini running 10.4.9.
Bob GallantHi Bob,
It works for me.
Find will only search in selected calendars. Do you have the relevant calendars checked in the calendar list? (you can select all calendars by Command-Clicking one checkbox)
Best wishes
John M
Maybe you are looking for
-
Can someone please help
-
ITunes won't open after FW migration between G5 10.4.11 and iMac 10.6.2
I just got my wonderful iMac i7 machine and used the migration assistant to move everything from my G5 OS 10.4.11 machine to the iMac. Everything has worked without a hitch except I have to re-active Photoshop and I had to re-input my Aperture serial
-
How to display logo in module pool screen
Hi, I need to display a logo in the screen of module pool programming. I have already imported the logo image using transaction OAER. Please suggest how to display the image in the screen.. Thanks and Regards, Sayan Ghosh
-
Restore iPhone failed but space still allocated in iPhone
Hi, I was restoring an iPhone 4 from a backup on iTunes after upgrading from 4.3.3 to 7.1.2. The restore appeared to have finished OK - I didn't actually see it finish but there was no message to indicated that it didn't The phone started to reboot a
-
hey, i aws wondering if someone could help me creating a flash file/ scene that can let users register and login....i have a server set up with ftp acces, php, mysql, databases, and other things. so if anyone could help me then post here plz....if u