Skip to content

Instantly share code, notes, and snippets.

@HoKim98
Created October 17, 2022 08:50
Show Gist options
  • Save HoKim98/b68c755454742245e9de4d014148e0d9 to your computer and use it in GitHub Desktop.
Save HoKim98/b68c755454742245e9de4d014148e0d9 to your computer and use it in GitHub Desktop.
SONiC Utilities
#!/usr/bin/env
# Copyright (c) 2022 Ho Kim (ho.kim@ulagbulag.io). 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
}
#!/usr/bin/env
# Copyright (c) 2022 Ho Kim (ho.kim@ulagbulag.io). 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