Simple shell script

When I was looking at one of my earlier posts, I noticed that sometimes I do repeat cli commands manually instead of scripting. Life is short! If you can’t find any other shell, junos has also C shell and following is a simple loop which generates several commands following a similar pattern. For example I would like to delete all ethernet-switching families
in one go in an SRX210 device. Then write the following lines into a file named junos.sh when you are in shell prompt then run it like below;


root@srx210%/bin/csh junos.sh

delete interface fe-0/0/2.0 family ethernet-switching
delete interface fe-0/0/3.0 family ethernet-switching
delete interface fe-0/0/4.0 family ethernet-switching
delete interface fe-0/0/5.0 family ethernet-switching
delete interface fe-0/0/6.0 family ethernet-switching
delete interface fe-0/0/7.0 family ethernet-switching

Then just paste the output under configuration command and commit!

#!/bin/csh

@ x =2
while ($x <= 7)
   echo "delete interface fe-0/0/$x.0 family ethernet-switching "
@ x +=1

end

About: rtoodtoo

Genco has worked for more than 10 years as a Network/Support Engineer. He is also interested in Python, Linux, Security and SD-WAN, currently lives in the Netherlands and works as a Network Support Engineer at Tesla Inc. // JNCIE-SEC #223 / RHCE / PCNSE


One thought on “Simple shell script”

  1. Or simply redirect it to “cli” with “configure private” in first and “commit” in last line. 🙂

Leave a Reply to Kaacz Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.