Compare actual files with format

Hi,

I have database table let say t_filenames which stores filenames and date_format in two columns.

e.g.

ABCD_TV_YYYYMMDD.txt                  YYYYMMDD
ABCD_MOUSE_YYYYMMDDHHMISS.txt           YYYYMMDDHHMISS

Actual files are available in a directory (say /tmp), actual files are with time/date details.
for e.g.

ABCD_TV_20160822.txt 
ABCD_MOUSE_20160814062822.txt

I would like to write a script to verify if all the files in the table are available over the directory. If exists create a dummy file if not just exist.

Could you please help me to solve this.

I tried to write a function which connects database and gets the filename and format. As a first step, the format would be replaced with ? marks and then used [[ ]] to verify if the file match. But not much success.

Thank you in advance.

Regards,
Pointers

Hello pointers1234,

I haven't have a real time scenario so didn't test this code, you could give it a try and let us know how it goes then.

cat script.ksh
### Here I am taking an example of sql db.
cat << EOF > sql_file.sql
select filenames from t_filenames;
EOF

sqlplus user_name/password@schema_name < sql_file.sql > output_file
#### Here we need to remove junk lines from file output_file which we will get once we connect to client. eg--> connected to: SQL*PLUS version etc.
which I can't predict until/unless you post output for above query with code tags here. So assuming we have removed those lines and have them into a file named output_file_names.
awk '{if($0 !~ /SQL*plus/ && $0 !~ /connected to/){print}}' output_file > output_file_names
while read line
do
	if [[ -f "/tmp/$line" ]]
	then
		echo "File named " $line " is present."
	else
		touch "/tmp/$line"
	fi
done < "output_file_names"

Though there could be more ways to perform this task, one could take this as a startup point.

Thanks,
R. Singh

Sorry for being late to confirm.

Thank you, it helped me to solve the issue.

Regards,
Pointers