Posted on April 28, 2016 5:49 pm
 |  Asked by Shawn
 |  2423 views
0
0
Print Friendly, PDF & Email

I am looking at running a script after a switch powers up. I have a few lines that I run from bash that helps with a radius/DNS slowness issue. I would love to be able to run this at startup so I don’t have to manually touch each switch after a power event.

Any ideas on how I can go about doing this locally on each device? Thanks EOS gurus.

0
Posted by Upasana Dangi
Answered on April 28, 2016 5:58 pm

Hi Shawn,

An event-handler which can trigger on switch bootup should work here.

For example:

Have the script saved under /mnt/flash/ so it persists across reboots and link it to the event handler:

switch(config)#show run section event-handler

event-handler boot-up-script

trigger on-boot

action bash /mnt/flash/script.sh

Marked as spam

Ok. I really thought this would be the best way, but it appears that the event-handler is not actually running the script on boot. I am not seeing the results I am expecting at least.

I have the script saved on the switch, and can manually execute the script with a ./ with no issues. If anyone has any suggestions, that would be great!! I have what all I think is relevant pasted below.

Script name: dns_fix.sh
Located on flash:
chmod of 755
The script:
#!/bin/bash
echo ’ echo ”UseDNS no” >> /etc/ssh/sshd_config ’ | sudo ip netns exec ns-MGMT bash
echo ’ echo ”UseDNS no” >> /etc/ssh/sshd_config-MGMT ’ | sudo ip netns exec ns-MGMT bash
echo ’ /sbin/service sshd restart ’ | sudo ip netns exec ns-MGMT bash
echo ’ /sbin/service sshd-MGMT restart ’ | sudo ip netns exec ns-MGMT bash

The event-handler config:
event-handler dns-fix
trigger on-boot
action bash /mnt/flash/dns_fix.sh

(Shawn at May 2, 2016 11:41 am)
0
Posted by Gary Nigg
Answered on April 28, 2016 5:59 pm

Create a /mnt/flash/rc.eos file and put the contents of your shell script there. This should do what you want.

2
Posted by Jeremy Georges
Answered on April 28, 2016 6:07 pm

To add to Upasana & Gary’s comments.

 

It depends on when you need your script to be executed.

If you want/need your script to be executed once EOS and various agents/daemons are up and running, then use the event-handler.

If you need your script to run very early in the boot process (such as modifying the CLI, over writing a daemon/agent, etc) then use an rc.eos file in /mnt/flash.

0
Posted by Shawn
Answered on April 28, 2016 6:43 pm

Thanks folks. I think the event handler is best. I did not even think about using it. This script is just the fix to the slow SSH issue due to DNS and the management vrf. The fix does not survive reloads, so this will be perfect.

a

Post your Answer

You must be logged in to post an answer.