lundi 8 avril 2019

Need help on ksh script to get output using if statement or the best - for Oracle SQL

I have Oracle output to a file. I need the script (ksh) to read file and based on the values do action.

I have 3 columns in output file (OF) - username, edate, and profile. I'll have to use the data from these columns as input to make action. Condition: 1. If the data in profile column starts with DBA_ and the data in edate column is greater than (sysdate-60) then send email warning using mailx.

  1. If the data in profile column starts with DBA_ and the data in edate column is greater than (sysdate-90) then lock user account.

This is for Linux server running ksh script. Oracle 11g and 12c.

Half baked code below and need help to develop this into working script with the above logic/requirement. Not sure how to use file inputs into script file to SQL plus to execute.

if [ cat $dbaexpired_users |grep -ic DBA_ -gt 0 ]; then cat $dbaexpired_users |col -x | $HOME/bin/notify "Take Action: Users EXPIRING in the next 30 Days" DBA_REPORT DB $ORACLE_SID Warning Report cat $dbaexpired_users |col -x | mailx -s "Warning - DATABASE $ORACLE_SID - Users EXPIRING in the next 30 Days" -r "dbsecurity-team@groupxxxx.com" else < ‘alter user username account lock;’> cat $dbaexpired_users |col -x | mailx -s "Account LOCKED - DATABASE $ORACLE_SID – User Account EXPIRED" -r "dbsecurity-team@groupxxxx.com" fi

From the file I can use the values that can send emails, need inputs as how to do the 2nd part to do SQL lock set of users using SQL .

Aucun commentaire:

Enregistrer un commentaire