We changed some usernames in our application however there are some history etc. in the database that also needs to be updated. There is a file update_users.list that has the old username and new username separated by space, 2 user names per line.
Would the below script be correct, or are there some noticeable issues with it?
#!/bin/bash
cat update_users.list | while read old_user new_user
do
sqlplus -s $user/$pass@$db > user_output.log <<EOF
UPDATE auf_kopf SET kopf_sach = '%${new_user}%' WHERE kopf_sach = '%${old_user}%';
UPDATE auf_prot SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE auf_prot_hint SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE ordhist SET user_code = '%${new_user}%' WHERE user_code = '%${old_user}%';
UPDATE liefer_daten SET sach_bearb = '%${new_user}%' WHERE sach_bearb = '%${old_user}%';
UPDATE shipment_head SET shipment_sach = '%${new_user}%' WHERE shipment_sach = '%${old_user}%';
UPDATE lager_bew SET lb_sachbearb = '%${new_user}%' WHERE lb_sachbearb = '%${old_user}%';
UPDATE lager_abzu SET abzu_sachbearb = '%${new_user}%' WHERE abzu_sachbearb = '%${old_user}%';
UPDATE best_kopf SET best_sach = '%${new_user}%' WHERE best_sach = '%${old_user}%';
UPDATE rcpt_header SET user_name = '%${new_user}%' WHERE user_name = '%${old_user}%';
UPDATE stat_kopf SET st_kopf_sach = '%${new_user}%' WHERE st_kopf_sach = '%${old_user}%';
UPDATE stat_mod SET stat_user = '%${new_user}%' WHERE stat_user = '%${old_user}%';
/
exit
EOF
echoin the beginning of each line. This way you will see the output without having it executed. Once you are sure it has no parsing problems, go and execute it.SP2-0734: unknown command beginning "echo "UPDA..." - rest of line ignored..