The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
printing all array values using dbx 7.2.1 JamesGoh High Level Programming 1 12-18-2007 04:07 PM
to assign cut values to an array Syms UNIX for Dummies Questions & Answers 6 10-29-2007 06:42 AM
Assigning values to an array yongho UNIX for Dummies Questions & Answers 4 07-13-2005 08:49 PM
array values in a command eeisken Shell Programming and Scripting 3 06-22-2005 04:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2008
jhillier jhillier is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
Question incorrect array values

I have a file with 2 lines and 3 filelds

-bash-3.00$ cat del_old_files.cfg
$DBA_WORK_DIR *sybdba* 30
$DBA_LOG_DIR *sybdba* 30


I have tried to set up arrays for each field (bash shell)

declare -a dirArray=`cut -d' ' -f1 < del_old_files.cfg`
declare -a nameArray=`cut -d' ' -f2 < del_old_files.cfg`
declare -a daysArray=`cut -d' ' -f3 < del_old_files.cfg`

when I query the array I get

-bash-3.00$ echo ${dirArray[0]}; echo ${nameArray[0]}; echo ${daysArray[0]}
$DBA_WORK_DIR $DBA_LOG_DIR
*sybdba* *sybdba*
30 30
-bash-3.00$ echo ${dirArray[1]}; echo ${nameArray[1]}; echo ${daysArray[1]}



logically I would expect the [0] and [1] queries to return only 1 value

Where did I go wrong?
  #2 (permalink)  
Old 01-04-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by jhillier View Post
Where did I go wrong?
what do you want to do actually?
  #3 (permalink)  
Old 01-04-2008
jhillier jhillier is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
I want to be able to build a find command to delete files older than the number

find `echo ${dirArrary[0]}` -name "`echo ${nameArray[0]}`" -mtime +`echo{daysArray[0]}` -exec rm {}\;
  #4 (permalink)  
Old 01-04-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Code:
#!/bin/sh
while read line 
do
    set -- $line
    find $1 -name \"$2\" -mtime +"$3"
done < file
  #5 (permalink)  
Old 01-04-2008
jhillier jhillier is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
this fails as it is not converting the variables $DBA_WORK_DIR and $DBA_LOG_DIR

-bash-3.00$ while read line ; do set -- $line; find $1 -name \"$2\" -mtime +"$3"; done < del_old_files.cfg
find: stat() error $DBA_WORK_DIR: No such file or directory
find: stat() error $DBA_LOG_DIR: No such file or directory

yet the find statement works outside of the while statement



find $DBA_WORK_DIR -name "*sybdba*" -mtime +30
produces the expected list of files
  #6 (permalink)  
Old 01-04-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by jhillier View Post
this fails as it is not converting the variables $DBA_WORK_DIR and $DBA_LOG_DIR

-bash-3.00$ while read line ; do set -- $line; find $1 -name \"$2\" -mtime +"$3"; done < del_old_files.cfg
find: stat() error $DBA_WORK_DIR: No such file or directory
find: stat() error $DBA_LOG_DIR: No such file or directory

yet the find statement works outside of the while statement



find $DBA_WORK_DIR -name "*sybdba*" -mtime +30
produces the expected list of files
How did you create your del_old_files.cfg? If you can, put in a real path instead of $DBA_WORK_DIR. Otherwise, you have to define these variables somewhere in the script, so that they contain path values
  #7 (permalink)  
Old 01-04-2008
jhillier jhillier is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 4
this fails as it is not converting the variables $DBA_WORK_DIR and $DBA_LOG_DIR

-bash-3.00$ while read line ; do set -- $line; find $1 -name \"$2\" -mtime +"$3"; done < del_old_files.cfg
find: stat() error $DBA_WORK_DIR: No such file or directory
find: stat() error $DBA_LOG_DIR: No such file or directory

yet the find statement works outside of the while statement



find $DBA_WORK_DIR -name "*sybdba*" -mtime +30
produces the expected list of files


output with set -x

-bash-3.00$ ./jjh
+ read line
+ set -- '$DBA_WORK_DIR' '*sybdba*' 30
+ find '$DBA_WORK_DIR' -name '"*sybdba*"' -mtime +30
find: stat() error $DBA_WORK_DIR: No such file or directory
+ read line
+ set -- '$DBA_LOG_DIR' '*sybdba*' 30
+ find '$DBA_LOG_DIR' -name '"*sybdba*"' -mtime +30
find: stat() error $DBA_LOG_DIR: No such file or directory
+ read line
-bash-3.00$

so how do I get rid of the single quotes?
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0