Been a lurker since ~2k and an active member since ~2k9. Threw a question to "AI" the other day to write a script to safely allow me to update an iptables chain that I need to implement remotely. The result is below. My question for the monks isn't a question. It's a request from an old timer to see if there are any newcomers who can rewrite this script in Perl, properly.

#!/bin/sh # apply-new-iptables.sh OLD=/root/iptables-old.rules NEW=/root/iptables-new.rules # backup current iptables-save > "$OLD" # apply new rules iptables-restore < "$NEW" # start rollback timer: restore OLD after 60s if not canceled ( sleep 60 && iptables-restore < "$OLD" ) & ROLLBACK_PID=$! echo $ROLLBACK_PID > /tmp/iptables-rollback.pid echo "New rules applied. To keep them, run: kill $(cat /tmp/iptables-r +ollback.pid) && rm /tmp/iptables-rollback.pid"

Hint: there is at least one hugely fundamental issue that AI hallucinated.

-stevieb

Update: Hablo espaņol si prefieres.


In reply to It's been a long time by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.