korn shell脚本中修改oracle数据库密码的sqlplus命令

Sqlplus command to change oracle database password in kornshell scipt

我正在编写一个脚本来更改 Oracle 数据库的密码。我能够成功获取数据库名称、user_id、旧密码和新密码。我有这个命令来更改旧密码并将其设置为新密码:

sqlplus -s /nolog << EOF 
connect ${USER_ID}/"${OLD_PASS}"@${DB_NAME} 
alter user ${USER_ID} identified by ${NEW_PASS} replace ${OLD_PASS};
/
exit
EOF

当我将结果存储到一个变量中并打印出该变量时,我收到一条错误消息:

ORA-00922: missing or invalid option.

我认为这与 alter user 命令有关。如何修复此命令,以便通过我的脚本成功更改密码?

由于您在 connect 字符串中用双引号将旧密码括起来,因此旧密码和新密码似乎都有特殊字符。您得到的错误与带有感叹号的任一密码一致;但也可以以数字开头,具有多字节字符等

From the documentaton:

You must enclose the following passwords in double-quotation marks:

  • Passwords containing multibyte characters.
  • Passwords starting with numbers or special characters and containing alphabetical characters. For example:

    "123abc"
    "#abc"
    "123dc$"  
    
  • Passwords containing any character other than alphabetical characters, numbers, and special characters. For example:

    "abc>"
    "abc@",
    " "
    

因此,将它们也包含在 alter user 中:

alter user ${USER_ID} identified by "${NEW_PASS}" replace "${OLD_PASS}";