Passing Variable in -mtime command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Passing Variable in -mtime command
# 1  
Old 05-07-2015
Passing Variable in -mtime command

Hi,
As the process of log cleanup, Im using the below command

Code:
 
find $DIR -mtime +3 -type f -exec gzip {} \;

The problem is I want to pass +3 as variable in my unix shell.
I have defined ZPDATE=+3 in my properties file and calling this property file in my script.

If i try the below, it says invalid argument in -mtime

Code:
 
find $DIR -mtime $ZPDATE -type f -exec gzip {} \;

.

Can you help me with this asap
# 2  
Old 05-07-2015
Works for me. Run it with the -x option set and post the output.
# 3  
Old 05-07-2015
Yes Rudic, it worked with
Code:
-x

another problem with this is it was not able to find the files recursively in directories.

For Eg, as per the below command
Code:
 
find $DIR -mtime +7 -type f -exec gzip {} \;

$DIR has many sub directories. Say if the directory was modifed within 7 days but the files inside it wasn't modified.

This command is not picking up all the files. it just checks the last modified time for directory and leaves but not the files inside it.

DIR
Code:
 
drwxr-xr-x * * * 4096 May  7 07:57 20150312

FILES inside 20150312

-
Code:
rw-r--r-- 1 * * * Apr 29 05:56 log.20150312.csv
-rw-r--r-- 1 * * * Apr 29 05:56 report.20150312.csv

The above command fails here. Can you help in processing the files inside directory as well.
# 4  
Old 05-07-2015
I can't reproduce what you are saying. On both my linux and FreeBSD systems the old files are found even though the directory itself was modified recently.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 05-08-2015
Hi Rudic,

Can you help me to perform this in a soft link (not the file or directory)

Code:
ls -lrt $TMP 
lrwxrwxrwx 1 * * 16 Apr 20 07:55 /home/deena/tmp -> /app/deena/tmp

Code:
 
find $TMP -mtime +4 -type f

is not giving any output
# 6  
Old 05-08-2015
How about reading man find yourself:
Quote:
OPTIONS
.
.
.
-P Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the file is a symbolic link, the information
used shall be taken from the properties of the symbolic link itself.


-L Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the
link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points). Use of this option
implies -noleaf. If you later use the -P option, -noleaf will still be in effect. If -L is in effect and find discovers a symbolic link to a subdirectory dur‐
ing its search, the subdirectory pointed to by the symbolic link will be searched.
# 7  
Old 05-13-2015
Actually you need -H option here:
Code:
find -H $TMP ...

Alternative:
Code:
cd $TMP &&
find . ...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

2. Shell Programming and Scripting

Passing a variable to kill command

I have a script that kicks off several processes in the background and stored their pids in a variable as follows: PID_DUMP_TRAN=$PID_DUMP_TRAN" "$! so I then have a list of pids If I echo $PID_DUMP_TRAN I get back a list of pids e.g. 8210 8211 8212 However I then want to kill all these... (5 Replies)
Discussion started by: sjmolloy
5 Replies

3. Shell Programming and Scripting

Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example. (2 Replies)
Discussion started by: Anjan1
2 Replies

4. Shell Programming and Scripting

passing variable to sed command not working

Hello All, I am trying to embed variable in sed command to fetch a portion of record between two pattern. This command is not working ...any suggestion on this how to place the variable in sed command to find a portion . I am using Sun OS (Solaris). Thanks JM (1 Reply)
Discussion started by: jambesh
1 Replies

5. UNIX for Dummies Questions & Answers

Passing a command in a variable

I need to set up a strange system through which an arbitrary command is sent to a number of different servers (well, actually, VPS accounts). We have a command "vpass" that "passes" a command from the root level to resident VPS accounts. Suppose I wanted each VPS to do some trivial thing, like... (3 Replies)
Discussion started by: treesloth
3 Replies

6. Shell Programming and Scripting

Passing a variable to sed command

Hi guys, I wanted to pass a variable to the sed command which tells which line to be deleted. a=2; echo $a; sed '$ad' c.out it is throwing an error. sed: 0602-403 "$a"d is not a recognized function. I even tried "$a" and \$a.. but it is of no use. Can you please correct me... (6 Replies)
Discussion started by: mac4rfree
6 Replies

7. Shell Programming and Scripting

passing variable values to awk command

Hi, I have a situation where I have to specify a different value to an awk command, I beleive i have the gist of this done, however I am not able to get this correct. Here is what I have so far echo $id 065859555 This value occurs in a "pipe" delimited file in postition 8. Hence I would... (1 Reply)
Discussion started by: jerardfjay
1 Replies

8. Shell Programming and Scripting

Passing a variable to sudo sed command

hi, dataParse(){ line="$@" name="cat /etc/passwd | grep "$line": | cut -f6 -d':'" eval $name > sam.txt 2>&1 sudo -u $line sed -n 's/data-1/&/p' $name/test.xml >> sam1.txt } Here i getting the homedir of the accounts and is set in name variable.which returns "/home/raju" which i... (3 Replies)
Discussion started by: sachin.tendulka
3 Replies

9. Shell Programming and Scripting

Passing a variable in SED getting command garbled

I fairly new to SED. I have tried many different variations of this line of code and even breaking it down into its components and running them separately. They work individually without variables but when I place the $todbname variable it will either inserts the text "connect to $todbname"... (3 Replies)
Discussion started by: edewerth
3 Replies

10. Shell Programming and Scripting

Passing the command line argument in a variable

Hi, I am new to unix. Is their a way to pass the output of the line below to a variable var1. ls -1t | head -1. I am trying something like var1=ls -1t | head -1, but I get error. Situation is: I get file everyday through FTP in my unix box. I have to write a script that picks up first... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question