1

I want to insert the last modified timestamp of a file in the database within a shell script. My script goes like this

#!/usr/bin/ksh
date=date -r /raid/file/test.txt +%d" "%b" "%Y" "% r | awk '{print $1,$2,$3,$4,$5;}'
echo ${date}
sqlplus USR/[email protected] <<ENDOFSQL
INSERT INTO PROD_TABLE VALUES('$date');
exit
ENDOFSQL

I am wondering how to assign the last modified date of the file to a shell variable and use that inside sqlplus.Note that am looking for date in the format 05 May 2011 08:02:27 PM The $date is showing null at the moment and is getting inserted into the table. Would appreciate any recommendations around the same.

1 Answer 1

3

If you want the output of the date|awk stuff in your date variable, you need to capture it:

date=$(date -r /raid/file/test.txt +%d" "%b" "%Y" "% r | awk '{print $1,$2,$3,$4,$5;}')

Just that should do it but it has been a long time since I've used ksh. You don't need to access your date variable in sqlplus, you just need to access it in a string in your script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.