<html><head></head><body>+1 for getops<br><br>As long as the freeform comment is at the end, getops will be able to pull params if they are well defined. <br><br><div class="gmail_quote">On February 15, 2022 7:17:06 PM EST, DJPfulio--- via Ale <ale@ale.org> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">$ program option1 option2 option3 comment "this comment is \"bad\""<br><br>I'd use getopts. This works:<br><br>#!/usr/bin/env bash<br><br>echo "<br>Usage:<br>   $0 [-1] [-2] [-3] -s cidr-subnet comment<br>"<br><br>    while getopts '123s:' OPTION<br>    do<br>       case $OPTION in<br>        1) OPT1=1<br>             ;;<br>        2) OPT2=1<br>             ;;<br>        3) OPT3=1<br>             ;;<br>        s) SUBNET="$OPTARG"<br>             ;;<br>        h)    Usage<br>              exit 0<br>              ;;<br>       esac<br>    done<br># Get whatever is left. That's the comment, spaces are fine.<br>shift $(($OPTIND - 1))<br>COMMENT="$@"<br><br># Do more stuff here.<br>echo "CIDR=$SUBNET<br>Comment=$COMMENT"<br><br># end of test script.<br><br><br><br>On 2/15/22 10:06, Alex Carver via Ale wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">The comment is part of the command line for ipset, it's an integral part.<br><br>The original questions were more about bash parameter expansions than ipset since it could apply to other things as well.<br><br>On 2022-02-14 07:46, DJPfulio--- via Ale wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> If comments can be on the same line in the ipset file, the script is dumb enough to allow them.<br> If comments have to be placed onto a different line, I'd use getopts ... to accept 2 arguments and put the --comment input where it needs to go. The comment would be optional.<br><br> Or create another script based on the CIDR used and pulls the org+location from whois records.<br><br><br> On 2/14/22 01:38, Alex Carver via Ale wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"> Yeah, unfortunately that doesn't help because I do want to have the<br> comments sometimes.  I have some rulesets specific to entities so I<br> don't need them there but for a couple of the catch-all lists I need<br> the comments to remind me later.  That's the reason for the script,<br> to handle comments or not.<br><br> On 2022-02-13 20:31, DJPfulio--- via Ale wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"> My script to do this is 4 lines. No error checking. I didn't want<br> to overthink it. I don't even check that the euid is 0. That's<br> solved by placing the script in ~root/bin/.  K.I.S.S.<br><br> #!/bin/bash<br><br> IPSET_RULES_FILE="/etc/ipset.up.rules"<br><br> # Make a backup cp $IPSET_RULES_FILE $IPSET_RULES_FILE.bak<br><br> # Update the live ruleset - any errors? ipset add countryblock $1<br><br> # Append the new rule to the bottom echo "add countryblock $1 " |<br> tee -a $IPSET_RULES_FILE<br><br><br> On 2/13/22 17:50, Alex Carver via Ale wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;"> I'm putting a tiny utility script together to make it faster for<br> me to update ipset lists and add them to a restore file in one<br> shot but I've run into a slight hiccup with what I wanted to<br> accomplish.<br><br></blockquote> Lots of brilliant stuff deleted.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">Thoughts? _______________________________________________<br></blockquote><br> _______________________________________________ Ale mailing list Ale@ale.org <a href="https://mail.ale.org/mailman/listinfo/ale">https://mail.ale.org/mailman/listinfo/ale</a> See JOBS,<br> ANNOUNCE and SCHOOLS lists at <a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a><br></blockquote>_______________________________________________ Ale mailing list Ale@ale.org <a href="https://mail.ale.org/mailman/listinfo/ale">https://mail.ale.org/mailman/listinfo/ale</a> See JOBS,<br>ANNOUNCE and SCHOOLS lists at <a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a><br></blockquote><hr>Ale mailing list<br>Ale@ale.org<br><a href="https://mail.ale.org/mailman/listinfo/ale">https://mail.ale.org/mailman/listinfo/ale</a><br>See JOBS, ANNOUNCE and SCHOOLS lists at<br><a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a><br></blockquote><hr>Ale mailing list<br>Ale@ale.org<br><a href="https://mail.ale.org/mailman/listinfo/ale">https://mail.ale.org/mailman/listinfo/ale</a><br>See JOBS, ANNOUNCE and SCHOOLS lists at<br><a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a><br></blockquote><hr>Ale mailing list<br>Ale@ale.org<br><a href="https://mail.ale.org/mailman/listinfo/ale">https://mail.ale.org/mailman/listinfo/ale</a><br>See JOBS, ANNOUNCE and SCHOOLS lists at<br><a href="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</a><br></pre></blockquote></div><br>-- <br>Computers amplify human error<br>Super computers are really cool</body></html>