• Learning Map
  • Unix Quiz Center
  • Unix Professional Network
  • Just-Unix-No-Noise FB Group

unixadminschool.com

  • Home
  • Announcements
    • Feed
    • MISC
  • Beginners zone
    • Beginners Lessons
    • Career Guidance
  • Experts Zone
    • Cloud Computing
    • Configuration Solutions
    • Migrations
    • Network Design
    • Scripting
    • Server Security
    • SUN CLUSTERS
    • SUN LDOMS
    • Tools & Applications
    • Veritas Cluster Services ( VCS ) Learning
  • Intermediate Zone
    • Linux Learning
      • Linux Booting
      • Linux Disk Management
      • Linux LVM
      • Linux Networking
      • Linux Performance
      • Linux Troubleshooting
      • Linux YUM/RPM
      • Performance Analysis
      • Redhat Linux Kernel
      • RHEL 6
        • RHEL LDAP
        • Rhel6 Storage
      • Web Servers
    • Solaris Admin
      • Blog for Unix Admin
        • Storage Administration – SAN
      • Oracle Hardware
      • Reference Docs
      • Solaris 10 Zones & LDOMs
      • Solaris 11
      • Solaris Access Control
      • Solaris Best Practices
      • Solaris Booting
      • Solaris Disk Management
      • Solaris DNS
      • Solaris How-to
      • Solaris Installation
      • Solaris Kernel
      • Solaris Networking
      • Solaris NFS
      • Solaris NIS
      • Solaris Packages & Patching
      • Solaris Performance
      • Solaris Tips
      • Solaris Troubleshooting
      • Solaris User Authentication
      • solaris X86
      • Solaris ZFS and Boot Environment
      • Storage Configurations
      • SUN Hardware
      • Troubleshooting Flow charts
    • Veritas Admin
      • Veritas Netbackup
      • VxVM Learning
      • VxVM Troubleshooting
  • QUIZ Center
  • Vlabs

Subscribe

Scripting : Adding Static routes to remote Linux systems – Video

In our previous example we have discussed about a scenario , in which we have copied a script to each host and then we executed the script remotely using another calling script from the centralized host ( which is having publick key – password less authentication for each client ). But the problem in the previous scenario is we are making to connection to each host. And that is very expensive task in terms of network and time.

in real world, we will keep all the important scripts in a shared directory ( I mean NFS shared directory) and then we will call the client script using a remote calling script. In this way we can avoid the extra efforts require to copy the client script in each host every time when we modify the client script.

Coming to current scenario, I am showing you a demonstration of a task to remotely add a static route in each host mentioned in a hosts list file.

And actual route addition script will perform below checks before it actually add the route.

Check 1 : it will see if the route-eth0 already exists
IF YES – Go to Check 2
IF No – Go to check 3

Check 2: Check if the new entry already added in the file.
IF YES – Script will go for next check 3
IF No – script will add a entry to the route-eth0. And go for Check 3

Check 3: If the new route already enabled in the system
IF YES – Display Message and Exit
IF No – Go Forward for Route addition

Action : Enable New Entry added to Static route file

Final Check : Is the new route added properly
IF YES – Display Success message
IF No – Display Error

;

You can look at the Demo video for the execution of the Script: Access Video

Below are the Actual Scripts and Files Used In this Scenario:

Hosts list:

[root@gurkul01 Scripts]# cat hostlist
gurkul02
gurkul04

Calling Script ( From Centralized Server) :

[root@gurkul01 Scripts]# cat Call-Script.sh
#!/bin/bash

read -p “Enter the hostlist [Full Path] :” list
echo
read -p “Enter the Script you want to call :” prg
echo

if [[ -z $list || -z $prg ]] ; then
echo
echo -e “Error : Please enter the Valid hostlist and Script path”
exit 1
fi
echo -e “Running Script : $prg on hostlist : $list”
for host in `cat $list`
do
echo -e “::::\t $host”
ssh -q -i /root/.ssh/ssh-key.pem $host $prg 2>; /dev/null
done

[root@gurkul01 Scripts]#

;

Client Script that we are executing on each client host:

#!/bin/bash
host=`hostname`
pid=$$

Rt=”199.9.200.0/24 via 10.4.0.1 dev eth0″
RtFile=”/etc/sysconfig/network-scripts/route-eth0″
>;/tmp/rt-entry.$pid
>;/tmp/fileentry.$pid
echo -e “Check :::\tChecking for Static route File\t….”
echo
if [ -f $RtFile ]; then
echo -e “\t\tStatic route file exists\t…. “
echo
echo -e “Check :::\tChecking if route entry already Exists \t … “

if `grep ’199.9.200.0′ $RtFile 1>; /tmp/fileentry.$pid` ; then
echo -e “\t\tBelow entry already exist\t…. “
echo
echo “==============================================================”
cat /tmp/fileentry.$pid
echo “==============================================================”
echo
else
echo -e “\t\tFile had no entry for the new route .. Adding entry\t…”
echo -e $Rt >;>; /etc/sysconfig/network-scripts/route-eth0
echo

fi

echo -e “Check :::\tChecking if the route entry already enabled\t …”

if `/bin/netstat -rn|grep ’199.9.200.0′ 1>; /tmp/rt-entry.$pid` ; then
echo -e “\t\t$host ::: Static route already enabled …. exiting “
echo
echo “==============================================================”
cat /tmp/rt-entry.$pid
echo “==============================================================”
echo
exit 1
fi

echo -e “\t\tRoute not enabled\t … “
echo

else
echo -e “\tStatic route file Doesn’t exist , Creating New one … “
echo -e $Rt >;>; /etc/sysconfig/network-scripts/route-eth0
echo
fi

echo
echo -e ” Action :::\tEnabling new Routes on interface eth0″

/etc/sysconfig/network-scripts/ifup-routes eth0 2>;/dev/null
echo ” …………….”
echo -e “Check :::\tchecking for the new Route added …..”
if [ ! `/bin/netstat -rn|grep '199\.9\.200\.0' >; /tmp/rt-entry.$pid` ]; then
echo -e “\t\t$host ::: New route added successfully”
cat /tmp/rt-entry.$pid
echo
else
echo -e “\t\t$host ::: Error: Route add failed ,check manually”
echo
fi

;

Test Case 1 : We are checking the execution of the script with an existing /etc/sysconfig/network-scripts/route-eth0 but the new static route is not exists in the file, on both the hosts.

The Output of the Calling Script:

;

[root@gurkul01 Scripts]# ./Call-Script.sh

Enter the hostlist [Full Path] : /Scripts/hostlist
Enter the Script you want to call : /Scripts/add-static-route.sh

Running Script : /Scripts/add-static-route.sh on hostlist : /Scripts/hostlist

:::: gurkul02

Check ::: Checking for Static route File ….
Static route file exists ….

Check ::: Checking if route entry already Exists …
File had no entry for the new route .. Adding entry …

Check ::: Checking if the route entry already enabled …
Route not enabled …
Action ::: Enabling new Routes on interface eth0

Check ::: checking for the new Route added …..
gurkul02 ::: New route added successfully
199.9.200.0 10.4.0.1 255.255.255.0 UG 0 0 0 eth0

:::: gurkul04

Check ::: Checking for Static route File ….
Static route file exists ….

Check ::: Checking if route entry already Exists …
File had no entry for the new route .. Adding entry …

Check ::: Checking if the route entry already enabled …
Route not enabled …

Action ::: Enabling new Routes on interface eth0

Check ::: Checking for the new Route added …..
gurkul04 ::: New route added successfully
199.9.200.0 10.4.0.1 255.255.255.0 UG 0 0 0 eth0

;

In this Below case, we are actually running the script on two host which are actually having the new route configured and enabled. And in this case, the expected result from the script is exit from the check 3.

;

[root@gurkul01 Scripts]# ./Call-Script.sh

Enter the hostlist [Full Path] : /Scripts/hostlist Enter the Script you want to call : /Scripts/add-static-route.sh

Running Script : /Scripts/add-static-route.sh on hostlist : /Scripts/hostlist

:::: gurkul02

Check ::: Checking for Static route File ….
Static route file exists ….

Check ::: Checking if route entry already Exists …
Below entry already exist ….
==============================================================
199.9.200.0/24 via 10.4.0.1 dev eth0
==============================================================
Check ::: Checking if the route entry already enabled …
gurkul02 ::: Static route already enabled …. exiting
==============================================================
199.9.200.0 10.4.0.1 255.255.255.0 UG 0 0 0 eth0
==============================================================

:::: gurkul04

Check ::: Checking for Static route File ….
Static route file exists ….

Check ::: Checking if route entry already Exists …
Below entry already exist ….

==============================================================
199.9.200.0/24 via 10.4.0.1 dev eth0
==============================================================

Check ::: Checking if the route entry already enabled …
gurkul04 ::: Static route already enabled …. exiting

==============================================================
199.9.200.0 10.4.0.1 255.255.255.0 UG 0 0 0 eth0
==============================================================

;

I will be adding more scripting examples ( along with demos) in further posts of this section. Just stay connected. You can subscribe the email updates on these posts by subscribing here

;

You might be interested to read below :


  • Virtual Lab : Get Your hands dirty with grep & RegEx

  • A tool that changes the way of system administration – PUPPET ( from puppetlabs)

  • Scripting : SVM Root Mirroring for SOLARIS

  • Scripting : Checking System Configuration remotely – video demo

  • Automation in System Administraton – are you a middle level unix admin? it is for you.

  • Quiz – Redhat Linux Intermediate Skills
  • Email
  • More
  • Print
  • Digg
Posted by Ramdev
1 comment so far
Tagged with: [ scripting, solaris error, solaris learning, solaris routes, Solaris Troubleshooting, static routes ]
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Comment on “Scripting : Adding Static routes to remote Linux systems – Video”

  • Warren
    26 February, 2013, 22:00

    Good answers in return of this query with solid arguments and describing everything regarding that.

Leave a Comment

Join to our Professional Network (of 1400+ unixadmins ) to receive Unix Administration and Job Updates -

Pages1

Don't Miss Updates

 

Beginners Zone

 

Unixadmin Careers

Server Hardware

Beginners Lessons

Troubleshooting-Flowchart

 

Intermediate Zone

 

Solaris Booting

Solaris Volume Manager

Storage Configurations

Solaris Networking

Solaris X86

Solaris ZFS

Solaris NFS

Solaris NIS

Solaris Patching

Solaris Booting

Solaris Kernel

Veritas Volume Manager

Solaris NIS

Logical Volume Manager

Linux Networking

Linux Disk Management

Linux Troubleshooting

 

Experts Zone 

 

Solutions

Scripting and Automation

Server Security

Veritas Cluster Services

Sun Cluster Services

Cloud Computing

SUN LDOMS

Copyright © 2009 unixadminschool.com. All rights reserved.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.