I have a requirement where I am facing some issues when i am trying to pass the argument to a function. Below is my requirement:
I have four kinds of csv file which have a filename with keywords table,schema, database and host. for ex below:
Rebecca_Delete_Schema_01.csv
Rebecca_Delete_Schema_02.csv
Rebecca_Delete_Host_01.csv
Rebecca_Delete_Database_01.csv
Amable_Delete_Database_02.csv
Raja_Delete_Database_03.csv
Rebecca_Delete_Table_01.csv
Samar_Delete_Table_02.csv
My requirement is to delete these files in the sequence of table,schema, database and then host using some application specific delete command.
The files have records like below:
/SVP3458.CDC.STAT.COM/ORACLE DATABASE PREST.db --Database
/SVP3458.CDC.STAT.COM/ORACLE DATABASE PREST/COMM/EMAIL_DETAIL.tbl-- Table
Similarly for host and schema.
The delete command while work directly on these identity strings. Below is my script:
process_deletecm()
{
ISCRED_PATH=/opt/IBM/InformationServer/Clients/iscreds/cli
cd $ISCRED_PATH;
sed -ie 's/ /\*/g ' $1
echo $1
for file in $(cat $1 )
do
for Asset in $(cat $file)
do
./iscred.sh deletecm -dom profiling:8006 -authfile file.auth -cm ''$Asset'' -f
done
done
}
DB_PATH=/opts/reports/AB/Table_Delete
for csvfile in $DB_PATH/*.[Cc][Ss][Vv]; do
filename="$(basename "$csvfile")"
if [[ "${filename,,}" = *table* ]]; then
echo $filename >> $DB_PATH/Tab_Delete_File.csv
elif [[ "${filename,,}" = *schema* ]]; then
echo $filename >> $DB_PATH/Sch_Delete_File.csv
elif [[ "${filename,,}" = *database* ]]; then
echo $filename >> $DB_PATH/DB_Delete_File.csv
elif [[ "${filename,,}" = *host* ]]; then
echo $filename >> $DB_PATH/Hst_Delete_File.csv
fi
done
process_deletecm $DB_PATH/Tab_Delete_File.csv
process_deletecm $DB_PATH/DB_Delete_File.csv
Through the functions i am trying to impose that order of execution.
The problem is while looping to the record level of each csv file. The "Asset"in the second loop is not bringing me the exact identity string .i.e the record (/SVP3458.CDC.STAT.COM/ORACLE DATABASE PREST.db) from the file as the delete command will work on each string only.
Can anyone tell me where i am getting wrong in the loop condition?
for Asset in $(cat $file)
is going to split the file into whitespace-separated words not lines. See also How to loop over the lines of a file? – steeldriver Jan 29 '20 at 16:11