|
I'm having a dumb. in KSH, if I do a simple cat <file> | grep <search> | sed <strip some stuff> I get the full display of everything from the file. However, I want to mail this from within the script, so I'm trying to foo=$(cat <file> | grep <search> | sed <strip some stuff>), then do a print ${foo}, I only ever get the last line that I want. Why am I dumb?
|
# ? Feb 11, 2021 19:55 |
|
|
# ? Jun 11, 2024 13:44 |
|
Try wrapping the whole thing in quotes: foo="$(cmd)". Also, check out shellcheck. It's a great linter for shell scripts.
|
# ? Feb 11, 2021 20:37 |
|
necrotic posted:Try wrapping the whole thing in quotes: foo="$(cmd)". Also, check out shellcheck. It's a great linter for shell scripts. So going on what I know from other scripts, the double quote is just preventing the expansion of the control characters, and that's what is causing the problem?
|
# ? Feb 11, 2021 20:50 |
|
Gothmog1065 posted:So going on what I know from other scripts, the double quote is just preventing the expansion of the control characters, and that's what is causing the problem? Yeah, I think the newlines are a problem. I haven't really done anything with KSH but wrapping things in quotes is almost always what you want to prevent issues.
|
# ? Feb 12, 2021 16:49 |
|
I'm in the US and had to set up a Google business property just the other day and we have to wait for a postcard in the mail from them with a verification code.
|
# ? Feb 14, 2021 05:04 |
|
Can you think of a better way to verify a valid business address?
|
# ? Feb 14, 2021 05:14 |
|
I think that was another anecdote for the "does anyone send physical mail to verify addresses" discussion upthread, not a complaint?
|
# ? Feb 14, 2021 08:27 |
|
I'm working on a few scripts to check when I've been quoted in a thread, by searching the forums when I ask it to, or on a timed basis (every x minutes, I'm not gonna flood the search, don't worry) Unfortunately, to do that, I need to let the site know that it's actually me via cURL when I send the PUT request to the search page. That gonna be possible at all?
|
# ? Feb 15, 2021 22:46 |
|
Python beginner question. I've noticed that a lot of Python tutorials (like this one which explains how to make a blog with Python) use terminal to install stuff and run commands. This is easy on a Mac since you can run Terminal easily on that IS. But I have no idea how this is done in Windows 10. And every resource I've looked at always shits on Windows 10 for its broken cmd prompt. Am I better off learning and using and learning Python on Ubuntu? Because I really don't mind dual booting Windows + Ubuntu. I'm just getting kind of irritated that most tutorials assume you're on a Mac/Linux and I think I've spent way too much time trying to figure out how to get these Terminal commands working on Windows. melon cat fucked around with this message at 23:13 on Feb 15, 2021 |
# ? Feb 15, 2021 23:08 |
|
melon cat posted:Python beginner question. I've noticed that a lot of Python tutorials (like this one which explains how to make a blog with Python) use terminal to install stuff and run commands. This is easy on a Mac since you can run Terminal easily on that IS. But I have no idea how this is done in Windows 10. And every resources I've looked at always shits on Windows 10 for its broken cmd prompt. Well, while they are right to point and laugh at Windows for its awful, awful """terminal""", I'll help you out: You can install a WSL (Windows Subsystem for Linux) terminal, I recommend 'Windows Terminal' from the Microsoft store. It's free. After that, you should be able to run most commands just fine. If it's saying something about a python or pip command not being recognized, make sure they're in your PATH. It'd also probably help if you told us what commands you're struggling with.
|
# ? Feb 15, 2021 23:11 |
|
hbag posted:I'm working on a few scripts to check when I've been quoted in a thread, by searching the forums when I ask it to, or on a timed basis (every x minutes, I'm not gonna flood the search, don't worry) Sure, you should be able to send the Cookie header in your request using the one you get from logging in. See man curl (1) --cookie method for this. You can save it off from a browser or just copy it out.
|
# ? Feb 15, 2021 23:24 |
|
Hed posted:Sure, you should be able to send the Cookie header in your request using the one you get from logging in. See man curl (1) --cookie method for this. You can save it off from a browser or just copy it out. Right, right, I was thinking it'd be a cookie thing, but I wasn't certain (or, at least, I didn't know if the cookies the site uses are one-time things that'll expire after a while). I'll give that a try.
|
# ? Feb 15, 2021 23:29 |
|
hbag posted:Well, while they are right to point and laugh at Windows for its awful, awful """terminal""", I'll help you out: This... is a helpful start. No tutorials or resources cut through the BS and told me to get Windows Terminal from the Microsoft Store the way you just did. They always just start straight from Terminal and start banging out commands. My biggest irritation with self-learning Python (esp. through YouTube videos) is that there seems to be two types of tutorials: A) "Welcome Python noobies! I'm going to show you how to print Hello World! Over and over and over." B) Advanced tutorials from webdev blogs that are titled like they're for newbies but jump straight into a bunch of intermediate level material and skip over a lot of things. Because I thought I had Python installed (downloaded and installed the .exe from python.org) . But when I ran "python -m venv env" in Terminal it said I didn't have it installed. Turns out I had to install python through the Microsoft Store. These are the sort of things that even the most basic tutorials don't bother mentioning. Another example is this one from Django Central. Their instructions for "Windows Users": code:
melon cat fucked around with this message at 23:57 on Feb 15, 2021 |
# ? Feb 15, 2021 23:35 |
|
melon cat posted:Python beginner question. I've noticed that a lot of Python tutorials (like this one which explains how to make a blog with Python) use terminal to install stuff and run commands. This is easy on a Mac since you can run Terminal easily on that IS. But I have no idea how this is done in Windows 10. And every resource I've looked at always shits on Windows 10 for its broken cmd prompt. An alternative to using WSL like hbag suggested is a console emulater like cmder so you can stay entirely in Windows-land. Generally if you're installing libraries with something like pip or conda there's not really any difference between python development in Windows or Linux, but if you ever find yourself needing to manually install binary dependencies Windows is gonna suck.
|
# ? Feb 15, 2021 23:58 |
|
...now to figure out which cookie I need. none of these seem to really be standing out, but I might just have a smooth brain.
|
# ? Feb 16, 2021 00:11 |
|
so far, i've tried using the bbuserid and bbpassword cookies (together), but it's giving me a 500 error. gonna try throwing sessionid into the mix, too, see if that solves it edit: no im a dumbass that was actually the current speed not an error code, i am having different issues
|
# ? Feb 16, 2021 00:21 |
|
hbag posted:so far, i've tried using the bbuserid and bbpassword cookies (together), but it's giving me a 500 error. gonna try throwing sessionid into the mix, too, see if that solves it the existence of a cookie called bbpassword is giving me hives
|
# ? Feb 16, 2021 00:24 |
|
redleader posted:the existence of a cookie called bbpassword is giving me hives yeah. it's hashed but still
|
# ? Feb 16, 2021 00:26 |
|
1. Open the developer console on the Network tab and make sure it's capturing 2. Make the search request you're interested in and inspect it 3. Use the "copy as curl" option, make sure that works from the terminal, then remove options from it until it stops working.
|
# ? Feb 16, 2021 00:26 |
|
xtal posted:1. Open the developer console on the Network tab and make sure it's capturing slight issue there when i try sending that unaltered POST request, i get an error saying "Query ID invalid or search results have expired"
|
# ? Feb 16, 2021 00:36 |
|
hbag posted:slight issue there Sounds search specific? Maybe something gets generated with each search submission like a CSRF token? The search form could be designed to prevent exactly what you're doing
|
# ? Feb 16, 2021 00:42 |
|
rt4 posted:Sounds search specific? Maybe something gets generated with each search submission like a CSRF token? The search form could be designed to prevent exactly what you're doing if thats the case whoever designed the search is a loving NERD
|
# ? Feb 16, 2021 00:44 |
|
hbag posted:if thats the case whoever designed the search is a loving NERD Paging Jeffrey of YOSPOS
|
# ? Feb 16, 2021 01:23 |
|
hbag posted:slight issue there I haven't checked but there is probably a request earlier than that that does the actual searching? Then uses a query ID to redirect to a page for showing the results.
|
# ? Feb 16, 2021 02:36 |
|
xtal posted:I haven't checked but there is probably a request earlier than that that does the actual searching? Then uses a query ID to redirect to a page for showing the results. nope, doesnt seem to be any earlier requests
|
# ? Feb 16, 2021 02:58 |
|
Yeah, probably need to scrape the page first, then find the search link which includes the search ID. The forums software isn’t exactly cutting edge API stuff. (I think the search function is resource limited. A lot of old VBulletin sites would have a timeout between searches.)
|
# ? Feb 16, 2021 14:04 |
|
smackfu posted:Yeah, probably need to scrape the page first, then find the search link which includes the search ID. The forums software isn’t exactly cutting edge API stuff. You think I get given a cookie, or something, when I navigate to the search page? That could work, but if there is a cookie, I'm having a hard time finding it. Seems to be the same everywhere. And, yeah, I know about the resource limiting.
|
# ? Feb 16, 2021 20:22 |
|
It's probably a CSRF token, which will appear as a hidden input on the form and not in a cookie. If that's the mechanism at play you will need to load the search form and pull out the token before you can programmatically send the search post. edit: just looked, there's no CSRF token. When you send send the POST query the server responds with a 302 Redirect which includes the search ID. necrotic fucked around with this message at 20:54 on Feb 16, 2021 |
# ? Feb 16, 2021 20:51 |
|
melon cat posted:This... is a helpful start. No tutorials or resources cut through the BS and told me to get Windows Terminal from the Microsoft Store the way you just did. They always just start straight from Terminal and start banging out commands. I think the issue here is that these tutorials assume you're familiar with how the terminal works and don't cover that (tbf, this is somewhat beyond the scope of a python tutorial). You can go the route of installing WSL, but you'll still have to learn the basics of how the linux terminal works (granted, there's more/better info online about how to use the linux terminal than the windows one). The likely issue with "Terminal it said I didn't have it installed" (although I can't be certain without the actual error text) was that it was installed, but it wasn't on the path. When you type "python ...." Windows will search what's called the path environment variable (which is just a list of directories) for a program named "python". If it can't find the program, you'll get an error like "'python' is not recognized as an internal or external command, operable program or batch file." Sometimes programs add their install locations to the path variable, sometimes they don't, sometimes there's a checkbox in the installer for this. The first install you did probably didn't add the directory to the path variable, but the install you did from the Mircrosoft Store did. Anyway my point is that you need a tutorial on the terminal itself and your python tutorials probably aren't going to help with that.
|
# ? Feb 16, 2021 21:34 |
|
You can also download pycharm for free if you're more comfortable in an IDE
|
# ? Feb 16, 2021 21:39 |
|
Plinkey posted:You can also download pycharm for free if you're more comfortable in an IDE I pretty much use pycharm if only for the super-easy virtualenv management. Works great, never really had a problem with it. But in all fairness, a fully-fledged IDE may be a bit much to digest at first as well.
|
# ? Feb 16, 2021 22:56 |
|
necrotic posted:It's probably a CSRF token, which will appear as a hidden input on the form and not in a cookie. If that's the mechanism at play you will need to load the search form and pull out the token before you can programmatically send the search post. oh, motherfucker, literally all i had to do was include the -L flag. now it works fine.
|
# ? Feb 17, 2021 01:11 |
|
...anybody happen to know how i could loop 'sed' 27 times, preferably entirely via a pipe? so far, every method of looping it ive tried acts as if its only ran it once, since i assume it all runs at the same time instead of one after the other
|
# ? Feb 17, 2021 03:27 |
|
Not sure I understand what that means, what are you working with now?
|
# ? Feb 17, 2021 04:24 |
|
xtal posted:Not sure I understand what that means, what are you working with now? code:
|
# ? Feb 17, 2021 04:27 |
|
hbag posted:But the final 'sed', despite the runx function telling it to run 27 times, only seems to run once, as only the last line is removed (instead of the last 27, like i need) If you just want to remove the last n lines, why not just use head or something?
|
# ? Feb 17, 2021 04:36 |
|
Kilson posted:If you just want to remove the last n lines, why not just use head or something? because the system im writing this on is cool and uses a cool version of head where apparently negative numbers arent valid
|
# ? Feb 17, 2021 04:38 |
|
hbag posted:because the system im writing this on is cool and uses a cool version of head where apparently negative numbers arent valid So use wc to determine how many lines are in it, subtract n, then use head to grab the first len-n lines
|
# ? Feb 17, 2021 05:11 |
|
code:
|
# ? Feb 17, 2021 05:15 |
|
|
# ? Jun 11, 2024 13:44 |
|
leper khan posted:So use wc to determine how many lines are in it, subtract n, then use head to grab the first len-n lines This will require saving it to a file and assigning variables instead of doing it in one pipeline. Might be time to bust out a scripting language.
|
# ? Feb 17, 2021 05:20 |