Created
October 17, 2022 08:50
-
-
Save HoKim98/b68c755454742245e9de4d014148e0d9 to your computer and use it in GitHub Desktop.
SONiC Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env | |
# Copyright (c) 2022 Ho Kim ([email protected]). All rights reserved. | |
# Use of this source code is governed by a MIT license. | |
# define a macro function | |
function interfaces_do() { | |
# get all ethernet interfaces | |
declare -a INTERFACES_ALL=$(show interfaces status | grep -Po '^ *Ethernet\K(\d+)') | |
# get command line arguments | |
declare -a CMD=${@:1} | |
# iterate on each ethernet interface | |
for id in $INTERFACES_ALL; do | |
# replace all pattern '{}' to each interface id | |
declare -a cmd=("${CMD[@]/\{\}/$id}") | |
# execute the command | |
$cmd | |
done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env | |
# Copyright (c) 2022 Ho Kim ([email protected]). All rights reserved. | |
# Use of this source code is governed by a MIT license. | |
########################################################### | |
# Function: interfaces_do # | |
########################################################### | |
# execute your own commands | |
interfaces_do echo "Ethernet{}" | |
interfaces_do sudo config interface mtu Ethernet{} 9000 | |
########################################################### | |
# Others # | |
########################################################### | |
# save to file | |
sudo config save -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment