Database Reference
In-Depth Information
Many of the error-checking routines typical when prompting for user input have been removed for clarity: Did
the user provide answers? Were the department numbers entered in upper or lower case? Are they valid numbers?
Scalable and reliable scripts must always include those verifications.
#!/bin/bash
# ===============================================================
# File: change_admin_depts.sh
# Purpose: Change department number references for EM admins
# Parameters: None
# ===============================================================
read OLD_DEPT?"Enter the old department number: "
read NEW_DEPT?"Now enter the new department number: "
sqlplus <Connect String><<EOF
SET echo OFF
SET heading OFF feedback OFF page 999
spool old_department.lst
SELECT user_name
FROM sysman.mgmt_created_users
WHERE department = '${OLD_DEPT}';
spool off
exit
EOF
touch myARGFILE.lst
for thisUSER in `cat old_department.lst`; do
echo "modify_user -name="${thisUSER}"-department="${NEW_DEPT}">>myARGILE.lst
done
emcli argfile myARGFILE.lst
echo "\n\nDepartment settings after the change:\n"
sqlplus <Connect String><<EOF
SET echo OFF
SET heading ON pages 999
SELECT user_name,
department
FROM sysman.mgmt_created_users
ORDER BY user_name;
exit
EOF
[ old_department.lst ] && rm -f old.department.lst
[ myARGFILE.lst ] && rm -f myARGFILE.lst
The last two steps clean up the temporary files created at run-time. Every shell script should clean up after itself.
The syntax above checks for the existence of the file and removes it when one is found. You could also build a simple
if statement if you choose.
Search WWH ::




Custom Search