From vlug at palaceofretention.ca Fri Mar 1 17:51:27 2024 From: vlug at palaceofretention.ca (Mark G.) Date: Fri, 1 Mar 2024 17:51:27 -0800 Subject: [LinuxSIG] Linux Meeting Saturday, March 2, 2024 In-Reply-To: References: Message-ID: <0d88dbe7-65b3-4226-aef3-617a2d2a245b@palaceofretention.ca> Hi Ron, I have a bit of a head cold, so will be staying home. I will be online with the jitsi stream, but wanted to give the group a head's up that they'll need to provide their own jitsi laptop in the boardroom. Mark, the A/V guy. On 2024-02-28 21:49, rdebeck wrote: > Linux Meeting with remote attendance available > Saturday, March 2, 2024 > 9:30 AM to 11:30 AM PST > > This meeting will be an in person event with remote support, > > Get together, enjoy coffee, and talk Linux. Everyone is welcome. > > ? We'll be meeting in-person this month, as Quality Foods has > re-opened the board rooms. We will also setup a Jitsi laptop > in the board room for those attending remotely. > > For further details see: > > https://www.meetup.com/victoria-raspberry-pimakers-and-others/events/299298713/ > > From admin at bclug.ca Sat Mar 2 12:23:33 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sat, 2 Mar 2024 12:23:33 -0800 Subject: [LinuxSIG] bash_httpd.sh Message-ID: I asked ChatGPT to write an http server in bash. The chat is posted below - it's quite a nice bit of code, including comments, `mkfifo`, bash functions, `trap` statement, `awk`, `nc`, syntax highlighting, sub-shells, default listening port is 8080 - so no root privileges required,... There are a couple issues: * it doesn't pipe the output to the fifo, so output goes to the shell, not the browser / network * at the end, the fifo is left behind, so that needs manual deletion All in all, pretty nice. Would've taken me ages to come up with something that works (would've taken forever, 'cause I'd never attempt it). Wait, "pretty nice" is a bit of an understatement - this is absolutely amazing. > Write a simple web server in bash > Writing a simple web server in Bash can be a fun exercise, but keep > in mind that it might not be suitable for production use due to > limitations and potential security risks. Below is a very basic > example of a web server implemented in Bash: > #!/bin/bash > > # Define the port on which the server will listen PORT=8080 > > # Function to handle incoming requests handle_request() { # Read the > HTTP request from the client read -r request > > # Extract the request method and path method=$(echo "$request" | awk > '{print $1}') path=$(echo "$request" | awk '{print $2}') > > # Serve a simple response if [ "$method" = "GET" ]; then if [ "$path" > = "/" ]; then echo -e "HTTP/1.1 200 OK\r\nContent-Type: > text/html\r\n\r\n

Hello, World!

" > else echo -e "HTTP/1.1 404 Not Found\r\nContent-Type: > text/plain\r\n\r\n404 Not Found" fi else echo -e "HTTP/1.1 501 Not > Implemented\r\nContent-Type: text/plain\r\n\r\n501 Not Implemented" > fi } > > # Main loop to listen for incoming connections main() { echo > "Starting server on port $PORT..." mkfifo fifo trap "rm -f fifo" > EXIT > > # Continuously listen for connections while true; do # Wait for a > client to connect cat fifo | nc -l -p "$PORT" > >(handle_request) > done } > > main > Save the above code into a file, for example bash_web_server.sh, and > make it executable with chmod +x bash_web_server.sh. Then you can run > it with ./bash_web_server.sh. > > This script creates a basic HTTP server that listens on port 8080. It > can handle GET requests for the root path ("/") and returns a simple > "Hello, World!" HTML page. All other paths will result in a "404 Not > Found" response. Additionally, it returns a "501 Not Implemented" > response for any request method other than GET. > > Please note that this is a very basic implementation and lacks many > features found in real-world web servers, such as concurrency > handling, error checking, security measures, etc. It's more of a > proof of concept rather than something suitable for production use. From admin at bclug.ca Sat Mar 2 12:36:25 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sat, 2 Mar 2024 12:36:25 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: References: Message-ID: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> Another instance where ChatGPT gave invaluable help in coding was with an SQL problem I was having with joining 3 tables. I tried every combo of left join & right join, I tried CTEs, subqueries, and I just could not get it to work. Hours were spent trying to get a solution and I was left questioning my SQL knowledge. Interestingly, it took the table structure from this: > The tables: > > Table: Students > > +---------------+---------+ > | Column Name | Type | > +---------------+---------+ > | student_id | int | > | student_name | varchar | > +---------------+---------+ > student_id is the primary key (column with unique values) for this table. > Each row of this table contains the ID and the name of one student in the school. > > ... > The solution it spat out used a cross join and worked perfectly. A thousand online searches all lead to variations on basic "how to join 3 tables", making them useless. Again, incredibly impressed. This was ChatGPT 3.5 from about a year ago. rb From cvmiller at gmail.com Sat Mar 2 14:04:42 2024 From: cvmiller at gmail.com (Craig Miller) Date: Sat, 2 Mar 2024 14:04:42 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> Message-ID: <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> Ron, Good to hear you are having better luck than I. I suspect that 'bash' is low on the list of programming languages, and that is why AI models fair so poorly. There just isn't enough training data, compared to language like Python, or apparently, even SQL. Craig... On 3/2/24 12:36, Ron / BCLUG wrote: > > Another instance where ChatGPT gave invaluable help in coding was with > an SQL problem I was having with joining 3 tables. > > I tried every combo of left join & right join, I tried CTEs, > subqueries, and I just could not get it to work. > > > Hours were spent trying to get a solution and I was left questioning > my SQL knowledge. > > > Interestingly, it took the table structure from this: > >> The tables: >> >> Table: Students >> >> +---------------+---------+ >> | Column Name?? | Type??? | >> +---------------+---------+ >> | student_id??? | int???? | >> | student_name? | varchar | >> +---------------+---------+ >> student_id is the primary key (column with unique values) for this >> table. >> Each row of this table contains the ID and the name of one student in >> the school. > > > > ... > > > > > > The solution it spat out used a cross join and worked perfectly. > > > A thousand online searches all lead to variations on basic "how to > join 3 tables", making them useless. > > > > Again, incredibly impressed. > > > > This was ChatGPT 3.5 from about a year ago. > > rb > -- IPv6 is the future, the future is here ipv6hawaii.org From cvmiller at gmail.com Sat Mar 2 14:19:48 2024 From: cvmiller at gmail.com (Craig Miller) Date: Sat, 2 Mar 2024 14:19:48 -0800 Subject: [LinuxSIG] bash_httpd.sh In-Reply-To: References: Message-ID: <67422845-1743-4ccc-8423-5d2e7ceffc52@gmail.com> Ron, This is my complaint. It looks like bash code, but it doesn't run. I followed the instructions, made it executable, and then tried to run, and I get this: $ ./bash_web.sh ./bash_web.sh: line 6: HTTP: command not found ./bash_web.sh: line 9: syntax error near unexpected token `)' ./bash_web.sh: line 9: `'{print $1}') path=$(echo "$request" | awk '{print $2}')' OK, so the script is a little munged from the copy and paste. So I spend 15 minute cleaning that up and I get this: $ curl localhost:8080/ curl: (52) Empty reply from server So I stand by what I said, AI isn't good at bash programming. You want a job that won't fall prey to AI, use bash ;-) Craig.... On 3/2/24 12:23, Ron / BCLUG wrote: > #!/bin/bash > > # Define the port on which the server will listen PORT=8080 > > # Function to handle incoming requests handle_request() { # Read the > HTTP request from the client read -r request > > # Extract the request method and path method=$(echo "$request" | awk > '{print $1}') path=$(echo "$request" | awk '{print $2}') > > # Serve a simple response if [ "$method" = "GET" ]; then if [ "$path" > = "/" ]; then echo -e "HTTP/1.1 200 OK\r\nContent-Type: > text/html\r\n\r\n

Hello, World!

" > else echo -e "HTTP/1.1 404 Not Found\r\nContent-Type: > text/plain\r\n\r\n404 Not Found" fi else echo -e "HTTP/1.1 501 Not > Implemented\r\nContent-Type: text/plain\r\n\r\n501 Not Implemented" fi } > > # Main loop to listen for incoming connections main() { echo > "Starting server on port $PORT..." mkfifo fifo trap "rm -f fifo" > EXIT > > # Continuously listen for connections while true; do # Wait for a > client to connect cat fifo | nc -l -p "$PORT" > >(handle_request) done } > > main -- IPv6 is the future, the future is here ipv6hawaii.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From admin at bclug.ca Sun Mar 3 00:14:24 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sun, 3 Mar 2024 00:14:24 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> Message-ID: <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> Craig Miller wrote on 2024-03-02 14:04: > I suspect that 'bash' is low on the list of programming languages, and > that is why AI models fair so poorly. I'm not so sure - that list of features implemented in the script went beyond 99.9% of bash scripts I've ever encountered. I've never, ever used `mkfifo`. I virtually never see `trap` used - one is ten times more likely to see: `sudo curl ... | bash` I've seen ChatGPT use bash arrays too, which I always have to do a refresher on before I can use them. > This is my complaint. It looks like bash code, but it doesn't run. I > followed the instructions, made it executable, and then tried to run, > and I get this: Like you said, that's a copy / paste issue. Easy to make - emailing code isn't great, I'll admit. > $ curl localhost:8080/ > curl: (52) Empty reply from server > > So I stand by what I said, AI isn't good at bash programming. The only error ChatGPT made was failing to pipe the output to fifo - trivially easy to fix, and a boo-boo anyone could overlook. Also, the `trap` might be incorrectly placed, but I played around with it, changed the location and the signals, couldn't get anything to work in the 10 or so minutes I tried to get it working... So - Craig had copy / paste error, easily fixed & ChatGPT had a full script with missing pipe statements. It's a tie, but ChatGPT did a lot of extra lifting. > You want a job that won't fall prey to AI, use bash Not a lot of jobs are primarily bash scripting. And, for the few seconds it took to get a working bash http server, using features most Linux users have never encountered, I'm not so sure bash scripting knowledge is job security. If there's 10 bash scripters on staff (there aren't), replace 9 of them with a ChatGPT account and have the tenth person review the output. As the kids say, "10x improvement". My 2?. rb From admin at bclug.ca Sun Mar 3 00:18:40 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sun, 3 Mar 2024 00:18:40 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> Message-ID: <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Ron / BCLUG wrote on 2024-03-03 00:14: > Also, the `trap` might be incorrectly placed, but I played around with > it, changed the location and the signals, couldn't get anything to work > in the 10 or so minutes I tried to get it working... On the other hand, this could be a user error. I "sourced" the script instead of changing to executable. There may also be shopt or `set` options that control how `trap` works, but I don't care enough to investigate. Honestly, I'm still amazed it's possible to write an http server in bash, my first thought was, "can't be done". Now, instead, I think "it shouldn't be done". But on a minimally spec'd router, it makes sense and is a clever idea, gotta admit. rb From dhylands at gmail.com Sun Mar 3 07:33:55 2024 From: dhylands at gmail.com (Dave Hylands) Date: Sun, 3 Mar 2024 07:33:55 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Message-ID: There are still some things I prefer to use bash for rather than Python (usually involving transforming the output of a program). But yeah it?s amazing what you can do with a well crafted bash script. I tend to use trap a lot more in scripts that get used in a more production environment. I?ve also found myself putting the incantation: `set -Eeuo pipefail` at the top of all my bash scripts. This page gives an detailed explanation of most of what that means: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3935570 The -E makes trap statements get inherited by shell functions. I find these options to be extremely useful, especially in build commands involved by make. Otherwise lots of failures were silently being absorbed rather than halting the build. Dave Hylands Peachland, BC, Canada http://www.davehylands.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From admin at bclug.ca Sun Mar 3 12:38:41 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sun, 3 Mar 2024 12:38:41 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Message-ID: <773c6e9a-cd42-428b-8038-cd7f4b4a8823@bclug.ca> Dave Hylands wrote on 2024-03-03 07:33: > There are still some things I prefer to use bash for rather than Python > (usually involving transforming the output of a program). But yeah it?s > amazing what you can do with a well crafted bash script. Indeed. It's powerful, if also rather painful. > I tend to use trap a lot more in scripts that get used in a more > production environment. Yeah, ditto. Even then, I usually fail to add them. > I?ve also found myself putting the incantation: > > `set -Eeuo pipefail` > > at the top of all my bash scripts. > > This page gives an detailed explanation of most of what that means: > https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3935570 Great resource! Following the link to the original version is worthwhile too. I think I'll remember it better after that summary. (I think I've said similar before though.) > The -E makes trap statements get inherited by shell functions. Handy! I'm reminded of a neat utility Nick Holland demonstrated at an online presentation a while back: Try, Cry, Die (he calls it Try, Yell, Die): ## Nick Holland SemiBUG lecture: ## https://egoslike.us/semibug/shellscriptingtips2.html ## ## http://www.mpaoli.net/~michael/unix/sh/ yell() { echo "$0: $*" >&2; } die() { yell "$*" ; kill -s SIGINT $$; } ## exit 111; } try() { "$@" || die "cannot $*" ; } Thanks for the `set` reminder Dave! rb From admin at bclug.ca Sun Mar 3 12:43:37 2024 From: admin at bclug.ca (Ron / BCLUG) Date: Sun, 3 Mar 2024 12:43:37 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Message-ID: Ron / BCLUG wrote on 2024-03-03 00:18: >> Also, the `trap` might be incorrectly placed, but I played around with >> it, changed the location and the signals, couldn't get anything to >> work in the 10 or so minutes I tried to get it working... > > On the other hand, this could be a user error. > > I "sourced" the script instead of changing to executable. Some playing around seems to indicate that running the script directly instead of sourcing it makes a difference. The `trap` is working now - Ctrl+C kills server, it traps the exit condition and cleans up the `fifo` file. User (me) error... This leaves no doubt, ChatGPT is a better bash programmer than I am. And probably better than 99% of Linux users out there. And... it's not even tuned to coding like CoPilot, it's just an LLM. Yikes. rb From cvmiller at gmail.com Sun Mar 3 13:27:30 2024 From: cvmiller at gmail.com (Craig Miller) Date: Sun, 3 Mar 2024 13:27:30 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Message-ID: <8e14a474-5ba4-4f5f-abf2-9d7df636f65a@gmail.com> Ron, I am glad you have it running. I think I'll stick with my web searching for bash code for now. There's something to be said for internet tested code (e.g. from existing github projects). But I can see LLMs getting better at writing code going forward. Craig... On 3/3/24 12:43, Ron / BCLUG wrote: > Ron / BCLUG wrote on 2024-03-03 00:18: > >>> Also, the `trap` might be incorrectly placed, but I played around >>> with it, changed the location and the signals, couldn't get anything >>> to work in the 10 or so minutes I tried to get it working... >> >> On the other hand, this could be a user error. >> >> I "sourced" the script instead of changing to executable. > > Some playing around seems to indicate that running the script directly > instead of sourcing it makes a difference. > > > The `trap` is working now - Ctrl+C kills server, it traps the exit > condition and cleans up the `fifo` file. > > > User (me) error... > > > This leaves no doubt, ChatGPT is a better bash programmer than I am. > > > And probably better than 99% of Linux users out there. > > And... it's not even tuned to coding like CoPilot, it's just an LLM. > > > Yikes. > > rb > > -- IPv6 is the future, the future is here ipv6hawaii.org From cvmiller at gmail.com Sun Mar 3 13:30:13 2024 From: cvmiller at gmail.com (Craig Miller) Date: Sun, 3 Mar 2024 13:30:13 -0800 Subject: [LinuxSIG] ChatGPT to write code [was: Re: bash_httpd.sh] In-Reply-To: References: <8d6810ff-64c7-47cf-bc3d-717c0ec379be@bclug.ca> <467f639d-93ce-4a2b-b673-0cbdbe6f065d@gmail.com> <057b3fa4-8b1e-402e-a425-08944cc20973@bclug.ca> <20e51b70-ed60-435b-b254-75b3c4b10a70@bclug.ca> Message-ID: <53a8069c-7f96-4fa0-bf4e-dad002efbd3e@gmail.com> Thanks for the pointer, Dave. I have made a note of it. Hopefully my future bash code will be better because of it. Craig... On 3/3/24 07:33, Dave Hylands wrote: > There are still some things I prefer to use bash for rather than > Python (usually involving transforming the output of a program). But > yeah it?s amazing what you can do with a well crafted bash script. > > I tend to use trap a lot more in scripts that get used in a more > production environment. > > I?ve also found myself putting the incantation: > > `set -Eeuo pipefail` > > at the top of all my bash scripts. > > This page gives an detailed explanation of most of what that means: > https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3935570 > > The -E makes trap statements get inherited by shell functions. > > I find these options to be extremely useful, especially in build > commands involved by make. Otherwise lots of failures were silently > being absorbed rather than halting the build. > > Dave Hylands > Peachland, BC, Canada > http://www.davehylands.com > > -- IPv6 is the future, the future is here ipv6hawaii.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From cvmiller at gmail.com Sat Mar 9 14:11:22 2024 From: cvmiller at gmail.com (Craig Miller) Date: Sat, 9 Mar 2024 14:11:22 -0800 Subject: [LinuxSIG] Room time conflict on 6 April Message-ID: <880b9683-5dc4-4260-8e32-ca13343b5d20@gmail.com> Hi All, Just a heads up, that the next Linux SIG is scheduled for earlier, as there is another group that has reserved the room at 10am on 6 April. I have reserved the room for 8:30-9:45. I won't be able to attend this meeting, as I will be traveling. all the best, Craig.... -- IPv6 is the future, the future is here ipv6hawaii.org From deid at drsol.com Sat Mar 9 17:56:02 2024 From: deid at drsol.com (Deid Reimer) Date: Sat, 09 Mar 2024 17:56:02 -0800 Subject: [LinuxSIG] Room time conflict on 6 April In-Reply-To: <880b9683-5dc4-4260-8e32-ca13343b5d20@gmail.com> References: <880b9683-5dc4-4260-8e32-ca13343b5d20@gmail.com> Message-ID: <4cebef0c-ef2a-4841-9755-1bedd5983a38@drsol.com> Hey Craig, Thanks for doing this. And, is the URL for your Llama presentation available? ?Deid va7rei? On Mar 9, 2024, 2:12 p.m., at 2:12 p.m., Craig Miller wrote: >Hi All, > >Just a heads up, that the next Linux SIG is scheduled for earlier, as >there is another group that has reserved the room at 10am on 6 April. > >I have reserved the room for 8:30-9:45. I won't be able to attend this >meeting, as I will be traveling. > >all the best, > >Craig.... > >-- >IPv6 is the future, the future is here >ipv6hawaii.org > >-- >LinuxSIG mailing list >LinuxSIG at vicpimakers.ca >http://vicpimakers.ca/mailman/listinfo/linuxsig_vicpimakers.ca -------------- next part -------------- An HTML attachment was scrubbed... URL: