LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need help writing Unix Shell script to pass file name,path,creation date ! (https://www.linuxquestions.org/questions/programming-9/need-help-writing-unix-shell-script-to-pass-file-name-path-creation-date-760395/)

windjashi 10-07-2009 04:27 PM

Need help writing Unix Shell script to pass file name,path,creation date !
 
Hi there
I'm new to UNIX scripting; I’m stuck with the following
I have an Oracle SQL script that takes three parameters
1- File Name
2- File Path
3- File creation date

Under UNIX I have a folder where files will be placed frequently and I need to upload those files to Oracle, what I need is a UNIX script that can do the following
Loop through Directory "/home/applmgr/snktmp"
Picks only files
Pass the file name to parameter &1
Pass the file path to parameter &2
Pass the file creation date to parameter &3

Call Oracle Script passing parameters &1,&2,&3
End loop

Is the above possible? I already knows how to call the Oracle Script from UNIX
I’m only stuck on writing the UNIX part where it List the files attribute(name,path,date) and store them to parameters ,Looping until the last file in the directory

If the above is not possible,then how can I create the below from the command line
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate

Thanks

slakmagik 10-07-2009 05:40 PM

Would
Code:

find -type f -printf "$ORACLE_CMD %h %f %c\n"
do? Not sure which timestamp you really need or in what format, but there are find flags for that.

windjashi 10-07-2009 06:00 PM

hi

can you explain the line ? what does it do ! i have subtituted the $ORACLE_CMD with directory , but i'm not getting the following error
Usage: find [-H | -L] path-list [predicate-list]

Thanks

slakmagik 10-07-2009 06:20 PM

Yeah - that should have been
Code:

find PATH_TO_FILES -type f -printf "ORACLE_CMD %h %f %c\n"
where you replace PATH_TO_FILES with the path you want and ORACLE_CMD with the command you mean to be giving. Find searches the directory looking for regular files (-type f) and prints a formatted line (-printf) composed of ORACLE_CMD, the path, the filename, and the changetime, followed by a newline.

However, this is actually dumb - it does isolate the data you want (I think) and can generate a secondary script you can use (redirect the output of the command to a file, chmod file, execute file) but doesn't do anything itself. If that isn't sufficient (and it probably isn't) I'll see about something more sensible. ;)

-- And maybe you can explain something to me - what does this mean?

Quote:

Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Does this mean your command wants the three data bits in the form of 'foo:bar:baz' or something? Because it matters if the command is expecting space separated args or not.

chrism01 10-08-2009 12:59 AM

@OP; just FYI, there's no such thing as creation date in *nix.
You've got ctime, mtime, atime see eg http://linux.die.net/man/1/find, none of which are creation time...


All times are GMT -5. The time now is 05:00 PM.