[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

AIX automation

I need someone to help write a script that will repeatedly used on our AIX servers. I would like to have friendly inputs and outputs to help notify the end user of what is going on. Providing tickers or notifications to user when install is in progress, waiting, or complete. Also, log errors to /tmp, anything fails. Install ssh and ssl.

0
AIX25
Asked:
AIX25
  • 3
  • 2
1 Solution
 
woolmilkporcCommented:
OK,

according to what I know from the previous Q:

-- Initialization and first step:
 
#!/bin/ksh
STEP="CAT I Remediation"
echo "You are about to start $STEP, would you like to continue? Enter yes or no."
read A; if ! echo $A | grep  -E -q "Yes|yes" ; then exit; fi
echo "Starting $STEP"

STEP="Store SSH Keys"
echo "You are about to start $STEP, would you like to continue? Enter yes or no."
read A; if ! echo $A | grep  -E -q "Yes|yes" ; then exit; fi
echo "Starting $STEP"

./maint/6100-01-03/save_sshkeys.ksh

if [[ $? -eq 0 ]]; then
   echo "$STEP succeeded"
     else echo "$STEP failed"
fi

Open in new window

-- Now for ssl/ssh
 
STEP="Install SSH"
echo "You are about to start $STEP, would you like to continue? Enter yes or no."
read A; if ! echo $A | grep  -E -q "Yes|yes" ; then exit; fi
echo "Starting $STEP"

cd /ssldir/openssl-0.9.8.1302
if [[ -f ./openssl-0.9.8.1302.Z ]]; then uncompress ./openssl-0.9.8.1302.Z; fi
tar -xf ./openssl-0.9.8.1302
inutoc /ssldir/openssl-0.9.8.1302/openssl-0.9.8.1302  
installp -aYX -d /ssldir/openssl-0.9.8.1302/openssl-0.9.8.1302  openssl.base openssl.license openssl.man.en_US >/dev/null

if [[ $? -eq 0 ]]; then
   echo "$STEP succeeded"
     else echo "$STEP failed"
fi

Open in new window

 
STEP="Install SSH"
echo "You are about to start $STEP, would you like to continue? Enter yes or no."
read A; if ! echo $A | grep  -E -q "Yes|yes" ; then exit; fi
echo "Starting $STEP"

cd /sshdir/openssh-5.4p1
if [[ -f ./openssh-5.4p1.Z ]]; then uncompress ./openssh-5.4p1.Z; fi  
tar -xf ./openssh-5.4p1
inutoc /sshdir/openssh_5.4p1
installp -aYX -d /sshdir/openssh_5.4p1 openssh.base openssh.license openssh.man.en_US >/dev/null

if [[ $? -eq 0 ]]; then
   echo "$STEP succeeded"
     else echo "$STEP failed"
fi

Open in new window

-- Now SNMP
 
STEP="SNMP Configuration Adjustment"
echo "You are about to start $STEP, would you like to continue? Enter yes or no."
read A; if ! echo $A | grep  -E -q "Yes|yes" ; then exit; fi
echo "Starting $STEP"

cp /etc/snmpd.conf /etc/snmpd.conf.$(date "+%Y%m%d%H%M").BAK
cp /etc/snmpdv3.conf /etc/snmpdv3.conf.$(date "+%Y%m%d%H%M").BAK

if grep -q "public" /etc/snmpd.conf ; then
   sed 's/public/mynewdomain/g' /etc/snmpd.conf > /etc/snmpd.conf.tmp
   mv /etc/snmpd.conf.tmp /etc/snmpd.conf
fi

if grep -q "public" /etc/snmpdv3.conf ; then
   sed 's/public/mynewdomain/g' /etc/snmpdv3.conf > /etc/snmpdv3.conf.tmp
   mv /etc/snmpdv3.conf.tmp /etc/snmpdv3.conf
fi

if [[ $? -eq 0 ]]; then
   echo "$STEP succeeded"
   echo snmpd.conf and snmpdv3.conf have been updated.
     else echo "$STEP failed"
fi

Open in new window

-- Finito.

Tickers or in-progress indicators are hard to implement in ksh.
It can be done by running the single steps in background and "ticking" while checking for existence of the backgroubd PID. But this is just too error-prone to do it just for fun. Is it really necessary?

Next, some hints to make the output look nice (?)
Just bolding:

BOLD=$(tput smso)
UNBOLD=$(tput rmso)

echo ${BOLD}SSH Keys are stored.${UNBOLD}

You can also use underlines. Bolding and underlining can be done with one attribute called "sgr", where:
All off:  
sgr 0 0
Underline on, bold off:
sgr 0 1
Both on:
sgr 1 1
Underline off, bold on:
sgr 1 0

So to underline and bold in one go:

BU=$(tput sgr 1 1)
NOBU=$(tput sgr 0 0)

echo ${BU}SSH Keys are stored.${NOBU}

Open in new window

And finally, if all errors shall go to an errorlog in /tmp:

Add as line 2 of the script, just after "#!/bin/ksh":

exec 2>/tmp/errorlog

Discarding stdout of the installp steps is already implemented.

wmp
0
 
AIX25Author Commented:
Reviewing
0
 
woolmilkporcCommented:
Any problems with the code above?

wmp
0
 
AIX25Author Commented:
Requesting attention omit lines
0
 
woolmilkporcCommented:
Pardon?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now