Shell string intercept--Get Oracle Group name

Source: Internet
Author: User

business background, when executing oracle file, need to authorize to the corresponding file, while we use chown-roracle:oraclegroup xxx, different server Oraclegroup The name is different, how to get it?

method: First, we can obtain oraclegroups by command groups Oracle, in the following format :

Oracle:oinstall DBA

How do I get the group name (oinstall)?

provide the following method 1: Use awk to get a third string

oraclegroup= ' groups oracle|grep-v Grep|awk ' {print $} '

If ["$oraclegroup" = ""]; Then

echo "There is no Oracle group"

Exit 1

Else

Chown-r Oracle: $oraclegroup $directory

Fi

method Two: Use A for loop to get the third element

groups= ' Groups Oracle '

Oraclegroup= ""

I=0

for element in $groups

Do

Let i++

if [[I-eq 3]]; Then

Export oraclegroup= $element

Echo$element

Break

Fi

Done

If ["$oraclegroup" = ""]; Then

echo "There is no Oracle group"

Exit

Else

Chown Oracle: $oraclegroup $targetfolder/init_upgrademanagement.sql

Fi


Shell string intercept--Get Oracle Group name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.