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

Worked for more than 10 years as a Network/Support Engineer and also interested in Python, Linux, Security and SD-WAN // 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. 🙂

You have a feedback?

Discover more from RtoDto.net

Subscribe now to keep reading and get access to the full archive.

Continue reading