I want to write a shell script to store OS current date - 1 day value in a variable.
Current Date is: 22042010 and new value is 21042010
I have multiple files having date value in name in ddmmyyyy format for multiple day, so I want to find all the files based on the date variable.
following is the list of files exists in /oracle/app/xml
The find command shoule be retrieve files: CUSTOMER_20-21042010.XML and ACCOUNT_20-21042010.XML and copy to a new folder.
I wrote script like below
I have also written below loop to extract the date value from file name and its working fine:
But it I always returned No files found to be copied.
I am not sure that whether I can use the variable in find command or not.
Experts help needed now.
Regards,
Hassan
Last edited by Scott; 04-22-2010 at 01:02 PM..
Reason: Code tags, please...
Several issues in the script.
Main problem is that the variable in the find line is between single quote characters. It will not get expanded.
Other issue is that when there is more than one file the find output would contain more than one filename. This is not good practice because it fails if filenames contain spaces and can generate a command which is too long.
Assuming you really mean to "cp" (not "mv") the files, here is a method broadly in your style.
Last edited by methyl; 04-22-2010 at 02:13 PM..
Reason: Corrections. And junk errors from "rm"
There are a couple areas for improvement of your shell script. However, to address your primary concern, yes you can use variables in the find command. However, to allow those variables to be interpreted, you will need to double-quote the find pattern:
One thing I notice is that you may want to pipe the output of your first find command to a variable, then create $var from an echo command piped to wc -l. In your second command, you can use something like:
This saves you having to execute the same find twice.
Now I have seen a problem regarding subtracting the <n> days from date.
As If the date is 01-APR-2010 then this script will subtract one day and new value will be zero i.e. 00042010 and the files of 31-MAR-2010 will not be copied. The same will heppen for 1st day of every month.
How would this situation handled?
Similarly when I used
It returned
The leading zero is not displaying means the files of day 2, daye 12, day 22 will be copied and this will also create the problem.
I want to know date is there is any statement/command /procedure to directly deduct <n> days from date i.e. we use
in oracle and then change the date format in "%d%m%y"
---------- Post updated at 01:43 PM ---------- Previous update was at 11:01 AM ----------
Hi All:
I am able to find one script on net at below address to resolved my error.
Although it is a too complex script to understand for persone like me who is a new in AIX scripting but very very helpful. This script is using date in "YYYYMMDD" format so I changed my script as below
Regards,
Last edited by lodhi1978; 04-23-2010 at 03:39 AM..
Reason: Adding more issue
Hi, I am new in scripting, and I am currently working on a script that will look for other files in a certain directory and exclude some file type.
this works fine:Find_File2Exclude=`find ${paths} -maxdepth 1 -type f \( ! -iname '*.out' ! -iname '*.auc' ! -iname '*.cps' ! -iname '*.log' ! -iname... (4 Replies)
Hi ,
I am executing 2 queries and output is saved in file1.txt and file2.txt
example of file1.txt
Testing word Doc.docx,/Lab/Development and Validation/Multitest/MT_010708/Testing,Development and Validation,root,11-Mar-2014,,,,,
Testing Excel _.xlsx,/Lab/Development and... (3 Replies)
Hi,
I am not able to get output for find command if there are variables defined inside -name option .
Please check below example
1)
###VARIABLES DEFINED
process="fast"
temperature="125c"
voltage="0p935v"
2) I don't get output for below find command
find -L <PATH> -type f \( -name... (2 Replies)
Hi,
I'd like to assign the output of the find command to a variable.
What I need is to run the find command, and if it returns zero files, the program exits.
so i'm trying to assign the output of the find command to the $var1 variable....and then if this is less than one, I echo a... (2 Replies)
I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use.
#!/bin/bash
CFS=$IFS
IFS=$(echo)
set dir = "/Users/apta/Library/Mail\... (3 Replies)
Hi
How to use a variable to store the filename of a file which was found by the 'find' command.
can this be practical-->var = find . -name "filename.dat"
Please help.. (1 Reply)
Hello Experts
I am newbie to unix and writing one script to make archive files
Problme i am facing is : I have used find command to find the type of files and I am storing find command results in a variable.
When I echo the variable I can see that path is printed properly but when i am... (5 Replies)
I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing.
But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Hi there,
I'm trying to find files that are greater then 30 days old, zip them and move to a different directory. I'm encountering an issue passing a variable (FilesToFind) to name within the find command. Here's the code I'm running:
#! /usr/bin/sh
FileDir=/home/ariba... (2 Replies)
I am working on a batch script where a filter is placed on a directory, and the files that come out of that filter have to be copied into another directory. More specifically, I am trying to set the results of a FIND command to a variable, so that I may access this variable / file later.
The... (2 Replies)