Trying to do multiple dir's and multiple file names etc.

What am I missing?

find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
#!/bin/ksh
#set -x
file_path1="/cddata/bi/logs/21l/data/cdr/"
file_path2="/cddata/bi/crm_ose/"
file_path3="/logs/21l/data/cem/"
file_path4="/logs/21l/data/archive/ "
file_path6="/logs/21l/data/dual4g/"
file_path7="/logs/6rl/data/backups/"
file_path8="/logs/p7p/data/backups/"
file_path9="/cddata/bi/"
file_path10="/cddata/bi2/"
file_nm1="dat"
file_nm2="sp_teoco_dly"
file_nm3="cl_dualmode_201"
file_nm4="gz"
daytype1=1
daytype2=10
daytype3=30
daytype4=90
find $file_path1/*$file_nm1* -type f -mtime +$daytype2 -exec ls -l {} \; ~/>>cleanup.log
find $file_path2/*$file_nm1* -type f -mtime +$daytype1 -exec ls -l {} \; ~/>>cleanup.log
find $file_path3/*$file_nm1* -type f -mtime +$daytype2 -exec ls -l {} \; ~/>>cleanup.log
find $file_path4/*$file_nm2* -type f -mtime +$daytype3 -exec ls -l {} \; ~/>>cleanup.log
find $file_path6/*$file_nm3* -type f -mtime +$daytype3 -exec ls -l {} \; ~/>>cleanup.log
find $file_path7/*$file_nm4* -type f -mtime +$daytype3 -exec ls -l {} \; ~/>>cleanup.log
find $file_path8/*$file_nm4* -type f -mtime +$daytype3 -exec ls -l {} \; ~/>>cleanup.log

The ls -l will be replaced with an rm -f once I see if it's working.

You need double quotes around $file_path1/*$file_nm1* etc...

find "$file_path1/*$file_nm1*" ....

--
BTW it is more efficient to use -exec ls -l {} + instead of -exec ls -l {} \;

(This is because with the second option a separate sub process is started for each and every result that find finds. With the first option as many results are added to the list of arguments as max line length allows and the command is only executed once for every set of arguments.. )

1 Like

Still not working, or maybe it means there aren't any files in there that age?

>cleanup.sh
find: 0652-019 The status on /cddata/bi/logs/21l/data/cdr/*dat is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /cddata/bi/crm_ose/*dat is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /logs/21l/data/cem/*dat is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /logs/21l/data/archive/*sprint_teoco_dly* is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /logs/21l/data/dual4g/*clearwire_dualmode_201* is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /logs/6rl/data/backups/*gz* is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
find: 0652-019 The status on /logs/p7p/data/backups/*gz* is not valid.
find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.

---------- Post updated at 02:03 PM ---------- Previous update was at 01:58 PM ----------

Code revised....

#!/bin/ksh
#set -x
file_path1="/cddata/bi/logs/21l/data/cdr/"
file_path2="/cddata/bi/crm_ose/"
file_path3="/logs/21l/data/cem/"
file_path4="/logs/21l/data/archive/ "
file_path6="/logs/21l/data/dual4g/"
file_path7="/logs/6rl/data/backups/"
file_path8="/logs/p7p/data/backups/"
file_path9="/cddata/bi/"
file_path10="/cddata/bi2"
file_nm1="dat"
file_nm2="sprint_teoco_dly"
file_nm3="clearwire_dualmode_201"
file_nm4="gz"
daytype1=1
daytype2=10
daytype3=30
daytype4=90
find "$file_path1/*$file_nm1" -type f -mtime +$daytype2 -exec ls -l {} + >> ~/cleanup.log
find "$file_path2/*$file_nm1" -type f -mtime +$daytype1 -exec ls -l {} + >> ~/cleanup.log
find "$file_path3/*$file_nm1" -type f -mtime +$daytype2 -exec ls -l {} + >> ~/cleanup.log
find "$file_path4/*$file_nm2*" -type f -mtime +$daytype3 -exec ls -l {} + >> ~/cleanup.log
find "$file_path6/*$file_nm3*" -type f -mtime +$daytype3 -exec ls -l {} + >> ~/cleanup.log
find "$file_path7/*$file_nm4*" -type f -mtime +$daytype3 -exec ls -l {} + >> ~/cleanup.log
find "$file_path8/*$file_nm4*" -type f -mtime +$daytype3 -exec ls -l {} + >> ~/cleanup.log

Oops I did not look well enough at your question. It should be something like

find "$file_path1" -name "*$file_nm1*" ....