How to list number of files through Crontab?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to list number of files through Crontab?
# 1  
Old 12-13-2010
How to list number of files through Crontab?

Hello All,

I am trying to put this line in Crontab (Linux box- x86_64), but the command is not running. Can you please help me out? My requirement is-

To find out the number of .csv files older than 1 day in directory /stage/landing. There are 2 other subdirectories under this directory also.

50 4 * * * test -d /stage/landing && find /stage/landing -mtime +1 -type f -exec 'ls -l *.csv | wc -l' "{}" \; >/dev/null 2>&1

Thanks,
Naresh
# 2  
Old 12-13-2010
Code:
find /stage/landing -mtime +1 -type f -name "*.csv" -exec wc -l {} \;

R0H0N
# 3  
Old 12-13-2010
It think that ROHON's version will count the number of lines in each file.

This will count the number of files. Bear in mind that the output will be in unix mail for the owner of the cron. You have no code to put the answer anywhere useful.

Code:
50 4 * * * [ -d /stage/landing ] && find /stage/landing -name '*.csv' -type f -mtime +1 -print | wc -l

# 4  
Old 12-13-2010
Quote:
Originally Posted by methyl
It think that ROHON's version will count the number of lines in each file.
Oh yes..!! I did a mistake in placing the wc -l. Thanks methyl for correcting me.Smilie
R0H0N
# 5  
Old 12-13-2010
Thanks buddies for your replies. By the way I tried like this, isn't it correct? I greped it (| wc -l).

20 11 * * * find /stage/landing -mtime +1 -type f -name "*.csv" | wc -l > /home/naresh/older1day.out 2>&1
# 6  
Old 12-13-2010
Quote:
Originally Posted by NARESH1302
Thanks buddies for your replies. By the way I tried like this, isn't it correct? I greped it (| wc -l).

20 11 * * * find /stage/landing -mtime +1 -type f -name "*.csv" | wc -l > /home/naresh/older1day.out 2>&1

this is same as what methyl has suggested.
R0H0N
# 7  
Old 12-13-2010
If in your original version you are trying to send error messages from "find" to /dev/null , I'd change the line slightly to prevent error messages appearing in your output file. I guess that your version of "find" does not need "-print" (some versions do, some versions don't).

Code:
find /stage/landing -mtime +1 -type f -name "*.csv" 2>/dev/null | wc -l > /home/naresh/older1day.out

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

2. Red Hat

How to list all crontab entries?

Hi, 1. How can I list all the crontab entries of all system users (like root, adm, sys etc.) as we have multiple files like /etc/crontab , /var/spool/cron, /etc/cron.d, /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly etc. 2. How can I list all the crontab entries of ALL users on a... (1 Reply)
Discussion started by: prvnrk
1 Replies

3. Shell Programming and Scripting

Process a specific number of files ina list

Hello, I have a list of files that was created with, FILES='./'$FOLD'/'$FOLD'_continue/'$OPTIMIZE_ON'/'*'out.txt' I am doing a loop on this list for INPUT in $FILES do ... done but I may not want to process everything. Is there a simple way to just process the first 5,10,n, etc in... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

4. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

5. Shell Programming and Scripting

List files only when a certain number of files match

Hi, I have many files named CCR20110720011001.CTRD CCR20110720011501.CTRD CCR20110720012001.CTRD CCR20110720012501.CTRD CCR20110720021001.CTRD ... (9 Replies)
Discussion started by: shadyfright
9 Replies

6. Shell Programming and Scripting

To get Port number alone from the list

~]#netstat -vatn | grep LISTEN tcp 0 0 0.0.0.0:34895 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN ... (7 Replies)
Discussion started by: linuxadmin
7 Replies

7. UNIX for Dummies Questions & Answers

list all files containing 4 digit number using grep

how can i list all files in my home directory that have a 4 digit id number, the line number where the id is located and the id itself not printing the entire line? (5 Replies)
Discussion started by: hobiwhenuknowme
5 Replies

8. UNIX for Dummies Questions & Answers

several crontab files

Hello. I am using the /etc/crontab files and it works well. I'd like to add the files located at /test/crontab Is there a way to register that /test/crontab? Should I add a special line to the /etc/crontab to call a the /test/crontab file as well? I am not sure what to do and I don't want to... (0 Replies)
Discussion started by: JCR
0 Replies

9. UNIX for Advanced & Expert Users

crontab: error on previous line; number out of bounds.

Hi, I am trying to set up a cron job for every Friday at 6:00 p.m. and got an error: "/var/tmp/aaaa29638" 1 line, 73 characters 00 18 00 0 5 /app/test/backup.ksh crontab: error on previous line; number out of bounds. Any ideas? Thanks! (1 Reply)
Discussion started by: oradbus
1 Replies

10. Shell Programming and Scripting

a list of number

Hi, I wrote a shell program and I need to only accept a list of numbers from 01 to 24 in my argument 1 ($1) before the program can continue. Does anyone know a better way to do it beside use the case command with 24 lines of condition? Thanks in advance! (6 Replies)
Discussion started by: whatisthis
6 Replies
Login or Register to Ask a Question