Open main menu

CDOT Wiki β

Changes

OPS235 Lab 6

556 bytes removed, 10:01, 27 June 2016
no edit summary
<ol><li value="5">We will now use an Associative Array along with a while loop to read every line in the ssh command in order to get network configuration file and store networking configuration from the '''centos1''', '''centos2''', and '''centos3''' VMsinto an array as a separate array element. Add the following content to your shell script editing session:</li></ol>
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
<br>
set centos1 centos2 centos3<br>for xwhile read line<br>
do<br>
&nbsp;read -p "Enter regular username for \"$x\" server: " userName[$x]<br>&nbsp;ssh ${userName[$x]}@$x "cat /etc/network/interfaces" > /tmp/network-$x.$$<br><br>&nbsp;index=0 # load each line into an array for VM<br>&nbsp;while read line<br>&nbsp;do<br>&nbsp;&nbsp;&nbsp;$x[$index]="$line"<br>&nbsp;&nbsp;&nbsp;index=$(($index+1))<br>&nbsp;done < /tmp/network-$x.$$<br>done1<br>
</code>
 <ol><li value="6">Finally, we will generate a web-page document, use a loop to printout the results of the data (stored in an array) and open the Associative Arrays) web-page document in a report file called: /root/networkthe '''firefox''' web-info.txtThe command at the end is a trick to remove all temporary files that have the same extension as the current PID number, therefore, it is uniquebrowser. Add the following content to your shell script editing session:</li></ol>
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
<br>
13,420
edits