How to develop apps for within shell?
I mean something like terminal train. Which language is used? Can you link me to a github repo for something similar?
https://redd.it/17enawo
@r_bash
I mean something like terminal train. Which language is used? Can you link me to a github repo for something similar?
https://redd.it/17enawo
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Command fails in noscript, but succeeds from SSH terminal window. WTH?!
I'm baffled. I have this folder called Documents and it has a directory called, `Dir with (parentheis) and apostrophe's and [square brackets]`. I created this very basic noscript to demonstrate the behavior I am seeing and seek help. Here is the code:
# !/bin/sh
dirname=/share/Documents
IFS=$'\n';
for d in $dirname**/Dir*; do echo ls "\"$d\"" 2>&1; ls "\"$d\"" 2>&1; break; done
When I run the noscript, I am getting the following:
# ~/dateadded.sh
ls "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]"
ls: cannot access "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]": No such file or directory
When I copy&paste the first line of output from the noscript into the same terminal window's prompt from which the noscript is run, I get this as a result:
# ls "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]"
total 20
4 drwxrwxr-x 2 admin administrators 4096 Oct 23 18:33 .
16 drwxrwxrwx 89 tntadmin administrators 12288 Oct 23 18:33 ..
That's what I am expecting from the noscript.
This server is a QNap NAS and I am running the noscript locally via a SSH terminal. I have tried running this with bash and sh. I have run `set` from the Terminal and from within the noscript and piped the output to files and put the differences into the noscript and (aside from the errors about read-only variables) still get the error. Enclosing the directory name in quotes should be sufficient but I even tried piping the directory name to `sed` to escape all the special characters. Still no love. I tried busybox and coreutils `ls` and `bash`. Nothing is working. I even tried running from Docker Containers running Ubuntu and Debian. STILL NO LOVE!
EDIT: I just tried changing the subdirectory of `$dirname` to a directory called `Scanned` that has absolutely no special characters at all. STILL NO LOVE!!!!!
Help?!
https://redd.it/17eyhzn
@r_bash
I'm baffled. I have this folder called Documents and it has a directory called, `Dir with (parentheis) and apostrophe's and [square brackets]`. I created this very basic noscript to demonstrate the behavior I am seeing and seek help. Here is the code:
# !/bin/sh
dirname=/share/Documents
IFS=$'\n';
for d in $dirname**/Dir*; do echo ls "\"$d\"" 2>&1; ls "\"$d\"" 2>&1; break; done
When I run the noscript, I am getting the following:
# ~/dateadded.sh
ls "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]"
ls: cannot access "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]": No such file or directory
When I copy&paste the first line of output from the noscript into the same terminal window's prompt from which the noscript is run, I get this as a result:
# ls "/share/Documents/Dir with (parentheis) and apostrophe's and [square brackets]"
total 20
4 drwxrwxr-x 2 admin administrators 4096 Oct 23 18:33 .
16 drwxrwxrwx 89 tntadmin administrators 12288 Oct 23 18:33 ..
That's what I am expecting from the noscript.
This server is a QNap NAS and I am running the noscript locally via a SSH terminal. I have tried running this with bash and sh. I have run `set` from the Terminal and from within the noscript and piped the output to files and put the differences into the noscript and (aside from the errors about read-only variables) still get the error. Enclosing the directory name in quotes should be sufficient but I even tried piping the directory name to `sed` to escape all the special characters. Still no love. I tried busybox and coreutils `ls` and `bash`. Nothing is working. I even tried running from Docker Containers running Ubuntu and Debian. STILL NO LOVE!
EDIT: I just tried changing the subdirectory of `$dirname` to a directory called `Scanned` that has absolutely no special characters at all. STILL NO LOVE!!!!!
Help?!
https://redd.it/17eyhzn
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What's the difference between running `unset array_var` and `unset array_var[*]` given array_var is an array variable?
`array_var` is an array variable.
**First step:**
I unset `array_var` by running this command: `unset array_var[*]`. After that I ran this command: `set | grep array_var` and this was the output:
_=array_var
**Second step:**
I unset `array_var` by running this command: `unset array_var`. And again, I run this command: `set | grep array_var` and I see the same output:
_=array_var
My CLI looks this now:
user@apple:~$ set | grep array_var
user@apple:~$ array_var=(one two three four five)
user@apple:~$ unset array_var[*]
user@apple:~$ set | grep array_var
_=array_var
user@apple:~$ array_var=(one two three four five)
user@apple:~$ unset array_var
user@apple:~$ set | grep array_var
_=array_var
user@apple:~$
So does that mean `unset array_var[*]` and `unset array_var` commands have the same purpose. I am not actually sure about this tho.
Also what does `_=array_var` mean?
Also another important thing I noticed is that, if we follow the steps in a reverse order (second step -> first step) `_=array_var` is not output when `set | grep array_var` is run. So that means `_=array_var` was created only when running `unset array_var[*]`. It will be nice if someone explained this too.
Thanks.
https://redd.it/17fa9w8
@r_bash
`array_var` is an array variable.
**First step:**
I unset `array_var` by running this command: `unset array_var[*]`. After that I ran this command: `set | grep array_var` and this was the output:
_=array_var
**Second step:**
I unset `array_var` by running this command: `unset array_var`. And again, I run this command: `set | grep array_var` and I see the same output:
_=array_var
My CLI looks this now:
user@apple:~$ set | grep array_var
user@apple:~$ array_var=(one two three four five)
user@apple:~$ unset array_var[*]
user@apple:~$ set | grep array_var
_=array_var
user@apple:~$ array_var=(one two three four five)
user@apple:~$ unset array_var
user@apple:~$ set | grep array_var
_=array_var
user@apple:~$
So does that mean `unset array_var[*]` and `unset array_var` commands have the same purpose. I am not actually sure about this tho.
Also what does `_=array_var` mean?
Also another important thing I noticed is that, if we follow the steps in a reverse order (second step -> first step) `_=array_var` is not output when `set | grep array_var` is run. So that means `_=array_var` was created only when running `unset array_var[*]`. It will be nice if someone explained this too.
Thanks.
https://redd.it/17fa9w8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
My Tips and Tricks for Bash Scripting After Writing Hundreds of Scripts
https://levelup.gitconnected.com/my-tips-and-tricks-for-bash-noscripting-after-writing-hundreds-of-noscripts-59987855b20a?sk=30564b4d311ac550cc2cfe4f0f426970
In this article I share my tips and best practices for writing noscripts in Bash.
https://redd.it/17fj8x0
@r_bash
https://levelup.gitconnected.com/my-tips-and-tricks-for-bash-noscripting-after-writing-hundreds-of-noscripts-59987855b20a?sk=30564b4d311ac550cc2cfe4f0f426970
In this article I share my tips and best practices for writing noscripts in Bash.
https://redd.it/17fj8x0
@r_bash
Medium
My Tips and Tricks for Bash Scripting After Writing Hundreds of Scripts
As a DevOps engineer, I’ve often encountered with Bash. Doing something on a server, writing CI/CD pipelines, or automating some manual…
How do I go about cracking this?
I am given a task as part of my assignment and I am not sure if I didnt understand the question or not, regardless of how much I try I am not able to crack this file. This is the question:
You are given a ciphertext for which you know the start of the corresponding plaintext: “Our shared secret word is: ” (excluding the quotation marks). The remainder of the plaintext consists of a single word from a dictionary file, with no spaces, carriage returns or line feeds added. The plaintext was encrypted using 128-bit AES with CBC mode using a single openssl enc command with no salting used, and using a password (also from the dictionary file) that is shorter than 16 characters, with a single digit from 0-9 appended to the word before encryption. A key was generated from the password using the SHA-256 message digest (as part of the same, single openssl enc command). Your goal is to write a program using a shell noscript that would find the password and the remainder of the plaintext. As part of your noscript you should use the commandline tools provided by openssl to encrypt and decrypt messages in order to perform a brute-force cryptanalysis. I have been at it for I don't know how long and I am unable to crack this.
The files provided are cipher.unknown and a words.txt the file format for the cipher is not given as it just says unknown. Please help me with this. even a simple explanation will be helpful for me. Thanks in advance
https://redd.it/17fmqma
@r_bash
I am given a task as part of my assignment and I am not sure if I didnt understand the question or not, regardless of how much I try I am not able to crack this file. This is the question:
You are given a ciphertext for which you know the start of the corresponding plaintext: “Our shared secret word is: ” (excluding the quotation marks). The remainder of the plaintext consists of a single word from a dictionary file, with no spaces, carriage returns or line feeds added. The plaintext was encrypted using 128-bit AES with CBC mode using a single openssl enc command with no salting used, and using a password (also from the dictionary file) that is shorter than 16 characters, with a single digit from 0-9 appended to the word before encryption. A key was generated from the password using the SHA-256 message digest (as part of the same, single openssl enc command). Your goal is to write a program using a shell noscript that would find the password and the remainder of the plaintext. As part of your noscript you should use the commandline tools provided by openssl to encrypt and decrypt messages in order to perform a brute-force cryptanalysis. I have been at it for I don't know how long and I am unable to crack this.
The files provided are cipher.unknown and a words.txt the file format for the cipher is not given as it just says unknown. Please help me with this. even a simple explanation will be helpful for me. Thanks in advance
https://redd.it/17fmqma
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Replacing underscores with " - " in folder and file names
I'm no stranger to bash but I'm out of practice. I'm trying to fix a huge archive of mp3's for someone and a ton of them used underscores and "illegal" characters in directory and filenames where it would read better to have a dash, i.e. "./Working/New/Classic_Country: Great Duets_Earl_Thomas_Conley_&_Tammy_Wynette-We_Believe_In_Happy_Endings.mp3:
Musicbranz Picard fixes all of this at the artist - noscript level, but the directory naming I just can't seem to fix with it's noscripting. I've been using a simple bash noscript to just pull all the files out of the folders into the "New" folder which helps, but the folder structure helps a lot with identifying the albums and artists.
So I've been tinkering with a noscript to loop through the folders and then the files to find any with underscores and special or illegal characters (\^A-Za-z0-9._) and replace them with " - " but I just can't seem to find the right command. I can pull the files or folders I want with something like this
find /home/serenity/Working/New -mindepth 1 -type d -name '*_*'| while read dir ; do echo "$dir" ; done
but I can't seem to apply something like this to it tomove them to a proper dir/name
| sed -e 's/[\^A-Za-z0-9._-\]/ - /g'
https://redd.it/17frvv4
@r_bash
I'm no stranger to bash but I'm out of practice. I'm trying to fix a huge archive of mp3's for someone and a ton of them used underscores and "illegal" characters in directory and filenames where it would read better to have a dash, i.e. "./Working/New/Classic_Country: Great Duets_Earl_Thomas_Conley_&_Tammy_Wynette-We_Believe_In_Happy_Endings.mp3:
Musicbranz Picard fixes all of this at the artist - noscript level, but the directory naming I just can't seem to fix with it's noscripting. I've been using a simple bash noscript to just pull all the files out of the folders into the "New" folder which helps, but the folder structure helps a lot with identifying the albums and artists.
So I've been tinkering with a noscript to loop through the folders and then the files to find any with underscores and special or illegal characters (\^A-Za-z0-9._) and replace them with " - " but I just can't seem to find the right command. I can pull the files or folders I want with something like this
find /home/serenity/Working/New -mindepth 1 -type d -name '*_*'| while read dir ; do echo "$dir" ; done
but I can't seem to apply something like this to it tomove them to a proper dir/name
| sed -e 's/[\^A-Za-z0-9._-\]/ - /g'
https://redd.it/17frvv4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
i'm a terrible journalist
### this is my journal editor setup
i keep using this noscript because it opens up the editor and names the file. if there was a previously named file it will show it side by side. keep the noscript here .local/bin/today
#!/usr/bin/env bash
# this journal for today
today=$(date +%Y-%m-%d).md
# last journal entry
past=$(ls -t1 *.md | head -n 1)
# open the editor like
if [ -f "$today" ]; then editor $today; else editor -O $today $past; fi
anybody have similar noscript helpers they use like this
https://redd.it/17fte6r
@r_bash
### this is my journal editor setup
i keep using this noscript because it opens up the editor and names the file. if there was a previously named file it will show it side by side. keep the noscript here .local/bin/today
#!/usr/bin/env bash
# this journal for today
today=$(date +%Y-%m-%d).md
# last journal entry
past=$(ls -t1 *.md | head -n 1)
# open the editor like
if [ -f "$today" ]; then editor $today; else editor -O $today $past; fi
anybody have similar noscript helpers they use like this
https://redd.it/17fte6r
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I time the bash processes blocking input
Bash is every now and then freezing while I'm typing a command.
Is there a way to time the "blocking" / unresponsiveness? A total time for the current session in bashrc somehow?
if my bash terminal is frozen waiting for lets say a tab completion on a dead fuse mount, time until its completed as in force closed, killed etc. Sry for my inability to explain it better/correctly.
In short, the time I waste and a way for me to track where its worst and how I can do better / look at whats going on. Maybe check the same in another shell with the history file etc. -Or is this stupidity?
https://redd.it/17g3h9w
@r_bash
Bash is every now and then freezing while I'm typing a command.
Is there a way to time the "blocking" / unresponsiveness? A total time for the current session in bashrc somehow?
if my bash terminal is frozen waiting for lets say a tab completion on a dead fuse mount, time until its completed as in force closed, killed etc. Sry for my inability to explain it better/correctly.
In short, the time I waste and a way for me to track where its worst and how I can do better / look at whats going on. Maybe check the same in another shell with the history file etc. -Or is this stupidity?
https://redd.it/17g3h9w
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
This Is My Most Complex Bash Script To Date
I made an Arch install noscript fully in Bash that sets up my system and my dot files with only three simple commands.
The whole thing is hosted on gitlab at https://gitlab.com/mclartydan0505/savageos and the idea is that now anywhere in the world I can get my full system setup from the command line to my custom desktop in minutes.
I know this is kind of moot as an Arch install noscript considering the one that comes by default is pretty good, but this noscript also downloads my Awesome config and all the apps I like with all the configs I like.
It is rather minimal, only installing about 600 packages by default. I am working on adding one file section the chroot to allow the user to add any additional apps they want to install, it is easy to do I just need to find the time to write it and commit it.
​
If you would like to run it in a vm or on hardware I could take the input for any errors, I did a sanity check in a QEMU VM with UEFI and it worked as planned, but I would like to know how hardware responds.
The hardest part is that the archlinux-keyring always seams to be breaking in the live iso, but I think I found a setup that can get the keyring to work 99% of the time so the noscript can download git and run the pacstrap.
https://redd.it/17g6hmw
@r_bash
I made an Arch install noscript fully in Bash that sets up my system and my dot files with only three simple commands.
The whole thing is hosted on gitlab at https://gitlab.com/mclartydan0505/savageos and the idea is that now anywhere in the world I can get my full system setup from the command line to my custom desktop in minutes.
I know this is kind of moot as an Arch install noscript considering the one that comes by default is pretty good, but this noscript also downloads my Awesome config and all the apps I like with all the configs I like.
It is rather minimal, only installing about 600 packages by default. I am working on adding one file section the chroot to allow the user to add any additional apps they want to install, it is easy to do I just need to find the time to write it and commit it.
​
If you would like to run it in a vm or on hardware I could take the input for any errors, I did a sanity check in a QEMU VM with UEFI and it worked as planned, but I would like to know how hardware responds.
The hardest part is that the archlinux-keyring always seams to be breaking in the live iso, but I think I found a setup that can get the keyring to work 99% of the time so the noscript can download git and run the pacstrap.
https://redd.it/17g6hmw
@r_bash
GitLab
Daniel McLarty / SavageOS · GitLab
Sticky shift key or one time caps lock
Hello, I'm trying to modernize a bit the input methods in my computer since we've (or at least I) been suffering for decades the same falencies.
What I want is a method for activating caps lock until a letter is entered and then deactivate it.
**O**btaining this result, without the need to press any combination of keys.
But I don't want sticky shift all the time I just want to be able to choose betwwen different methods.
***E***ven a different implentation of the same code, could work... ***L***ike this. ***I*** mean turning on and off capslock automatically each time that the '. ' sequence is entered.
I wrote a bash noscript to do so that works well in the terminal but when associated with a keyboard shortcut gets totally lost. I think that read has no idea where it is, here is my noscript:
!/bin/bash
echo $caps_state
while true; do
read -rsn1 input
for letter in {A..Z} {a..z}; do
echo $input = $letter
if [[ "$input" == $letter ]]; then
caps_state=$(xset -q|grep Caps|cut -d: -f3|tr -d ' ')
echo $caps_state
if ! [[ $caps_state == off01 ]]; then
echo caps off
xdotool key Caps_Lock
exit
fi
fi
done
done
What keylogger should I use?
https://redd.it/17ge8a1
@r_bash
Hello, I'm trying to modernize a bit the input methods in my computer since we've (or at least I) been suffering for decades the same falencies.
What I want is a method for activating caps lock until a letter is entered and then deactivate it.
**O**btaining this result, without the need to press any combination of keys.
But I don't want sticky shift all the time I just want to be able to choose betwwen different methods.
***E***ven a different implentation of the same code, could work... ***L***ike this. ***I*** mean turning on and off capslock automatically each time that the '. ' sequence is entered.
I wrote a bash noscript to do so that works well in the terminal but when associated with a keyboard shortcut gets totally lost. I think that read has no idea where it is, here is my noscript:
!/bin/bash
echo $caps_state
while true; do
read -rsn1 input
for letter in {A..Z} {a..z}; do
echo $input = $letter
if [[ "$input" == $letter ]]; then
caps_state=$(xset -q|grep Caps|cut -d: -f3|tr -d ' ')
echo $caps_state
if ! [[ $caps_state == off01 ]]; then
echo caps off
xdotool key Caps_Lock
exit
fi
fi
done
done
What keylogger should I use?
https://redd.it/17ge8a1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
at plays command immediatley
any one shed any light as to why bash plays the alarm sound immediately rather than waiting for the specified time ?
​
\#!/bin/bash
​
​
strHour=$(zenity --forms --noscript "simple alarm clock" --text "Combo Hoour" --add-combo "Select Hour." --combo-values "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24") && echo $strHour
​
​
​
strMinute=$(zenity --forms --noscript "simple alarm clock" --text "Combo Hoour" --add-combo "Select Minute." --combo-values "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59") && echo $strMinute
if zenity --question --text="Set Alarm for $strHour:$strMinute ?"; then
zenity --info --text="You pressed \\"Yes\\"!"
ffplay /home/dunryc/Wip/alarmclock/alarm.wav | at $strHour:$strMinute
else
zenity --info --text="You pressed \\"No\\"!"
fi
​
​
https://redd.it/17gjexs
@r_bash
any one shed any light as to why bash plays the alarm sound immediately rather than waiting for the specified time ?
​
\#!/bin/bash
​
​
strHour=$(zenity --forms --noscript "simple alarm clock" --text "Combo Hoour" --add-combo "Select Hour." --combo-values "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24") && echo $strHour
​
​
​
strMinute=$(zenity --forms --noscript "simple alarm clock" --text "Combo Hoour" --add-combo "Select Minute." --combo-values "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59") && echo $strMinute
if zenity --question --text="Set Alarm for $strHour:$strMinute ?"; then
zenity --info --text="You pressed \\"Yes\\"!"
ffplay /home/dunryc/Wip/alarmclock/alarm.wav | at $strHour:$strMinute
else
zenity --info --text="You pressed \\"No\\"!"
fi
​
​
https://redd.it/17gjexs
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Question about à Regular Expression
Hi,
I got a question regarding Regular expressions on Bash.
Currently doing the LPI exams, and one of the question is:
- What extented regular expression would match any mail address, like info@example.org ?
So came out with the following regex:
- Starts with alphanumeric char (at least 1)
- Followed by @
- Followed by at least one alphanumeric char or an hyphen or a dot
- Ending with 2 to 6 lower cases to match all kinds of domains (.xyz,.de,.com,.org,.museum and more)
In the given solution, here's the regex used:
Both regex works, but just by curisoty, what is the most efficient one ? the simplest or the more complex ?
As far as I understood
https://redd.it/17gv8zy
@r_bash
Hi,
I got a question regarding Regular expressions on Bash.
Currently doing the LPI exams, and one of the question is:
- What extented regular expression would match any mail address, like info@example.org ?
So came out with the following regex:
^[[:alnum:]]{1,}@([[:alnum:]]|-|\.){1,}\.[[:lower:]]{2,6}$
- Starts with alphanumeric char (at least 1)
- Followed by @
- Followed by at least one alphanumeric char or an hyphen or a dot
- Ending with 2 to 6 lower cases to match all kinds of domains (.xyz,.de,.com,.org,.museum and more)
In the given solution, here's the regex used:
"^\S+@+\S+\.\S+"
Both regex works, but just by curisoty, what is the most efficient one ? the simplest or the more complex ?
As far as I understood
is used to match any non-whitespace character but does it not includes specials chararacters such as question mark, exclamation mark and so on ? that are forbidden in a mail address ?
https://redd.it/17gv8zy
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Learning more
I know the basic stuff (variables, if else, read,echo,etc) how would I learn more and where can I?
https://redd.it/17gxcb2
@r_bash
I know the basic stuff (variables, if else, read,echo,etc) how would I learn more and where can I?
https://redd.it/17gxcb2
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Copy and rename file from shell noscript
This is a pretty basic question but I’ve been struggling getting this working for some reason. I am trying to copy a file from one directory to another and renaming it along with the copy. This is being done inside of a shell noscript, and I have a variable called $filename that stores the NEW file name. Here is the code snippet:
filename="IRcamfpgacksm${checksum}ver${version}.pdb"
#filename="Thisisafile.txt"
echo "filename: ${filename}"
cp ./par/ircamfpga/designer/impl1/*.pdb output/pl/$filename
The output of the echo command on the console is:
.pdbname: IRcamfpgacksmA415ver0x0081
But the file that gets copied to the new directory does not have the correct name. When I use the version of $filename that is commented out, it works perfectly fine.
https://redd.it/17gylgx
@r_bash
This is a pretty basic question but I’ve been struggling getting this working for some reason. I am trying to copy a file from one directory to another and renaming it along with the copy. This is being done inside of a shell noscript, and I have a variable called $filename that stores the NEW file name. Here is the code snippet:
filename="IRcamfpgacksm${checksum}ver${version}.pdb"
#filename="Thisisafile.txt"
echo "filename: ${filename}"
cp ./par/ircamfpga/designer/impl1/*.pdb output/pl/$filename
The output of the echo command on the console is:
.pdbname: IRcamfpgacksmA415ver0x0081
But the file that gets copied to the new directory does not have the correct name. When I use the version of $filename that is commented out, it works perfectly fine.
https://redd.it/17gylgx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
cURL: Need to make host server think I am a browser and not cURL.
I found a website that posts stats every month that are useful to my business. They post them for free.
The link to download a csv file, which is the format I need, looks like an API call:
https://gs.statcounter.com/os-market-share/tablet/chart.php?device=Tablet&devicehidden=tablet&statTypehidden=oscombined®ionhidden=ZA&granularity=monthly&statType=Operating%20System®ion=South%20Africa&fromInt=202209&toInt=202309&fromMonthYear=2022-09&toMonthYear=2023-09&csv=1
The problem I have, is if I paste that link in any browser, I get a CSV download. If I access it with wget or curl, I get a bit of useless XML data.
I suspect they are detecting client type to stop people doing this.
I simply want to write a noscript that pulls down certain datasets, then processes that so I can store the final data in a specific folder on my Nextcloud server. I want to use it for internal use (decision-making), but I want the data to be updated each month automatically, rather than me sit and manually download it each month.
I know cURL is super powerful and flexible, so can someone explain to me how I would get cURL to tell the host server that it is Firefox or Chrome or whatever?
Edit:
The problem I had was caused by a really stupid but easy to make mistake.
I ran the following:
curl https://gs.statcounter.com/os-market-share/tablet/chart.php?device=Tablet&devicehidden=tablet&statTypehidden=oscombined®ionhidden=ZA&granularity=monthly&statType=Operating%20System®ion=South%20Africa&fromInt=202209&toInt=202309&fromMonthYear=2022-09&toMonthYear=2023-09&csv=1
That output the following:
1 11976
2 11977
3 11978
4 11979
5 11980
6 11981
7 11982
8 11983
9 11984
10 11985
11 11986
2 Done devicehidden=tablet
[3] Done statTypehidden=oscombined
[4] Done regionhidden=ZA
5 Done granularity=monthly
6 Done statType=Operating%20System
7 Done region=South%20Africa
8 Done fromInt=202209
9 Done toInt=202309
10- Done fromMonthYear=2022-09
<chart caption='StatCounter Global Stats' subCaption="Top 5 Desktop Browsers in from - , 1 Jan 1970" anchorAlpha='100' showValues='0' bgColor='FFFFFF' showalternatevgridcolor='0' showalternatehgridcolor='0' bgAlpha='0,0' numberSuffix='%' canvasBorderAlpha='50' bgImage='https://www.statcounter.com/images/logogschartfadedpadded.png' bgImageDisplayMode='fit' canvasBgAlpha='0'
exportEnabled='1' exportAtClient='0' exportAction='download' exportFormats='PNG' exportHandler='https://gs.statcounter.com/export/index.php' exportFileName='StatCounter-browser--all--'
legendBorderAlpha='0' legendBgColor='000000' legendBgAlpha='0' legendPosition='RIGHT' legendShadow='0'
canvasBorderThickness='1' canvasPadding='0' showBorder='0' labelDisplay='Rotate' slantLabels='1'><categories></categories><styles>
<definition>
<style name='myCaptionFont' type='font' size='14' bold='1' isHTML='1' topMargin='14' />
</definition>
<application>
<apply toObject='Caption' styles='myCaptionFont' />
</application>
<definition>
<style name='myLegendFont' type='font' size='11' color='000000' bold='0' isHTML='1' />
</definition>
<application>
<apply toObject='Legend' styles='myLegendFont' />
</application>
<definition>
<style name='myHTMLFont' type='font' isHTML='1' />
</definition>
<application>
<apply toObject='TOOLTIP' styles='myHTMLFont' />
</application>
</styles>
</chart>
I forgot to put quotes around the url.
I do this:
curl
I found a website that posts stats every month that are useful to my business. They post them for free.
The link to download a csv file, which is the format I need, looks like an API call:
https://gs.statcounter.com/os-market-share/tablet/chart.php?device=Tablet&devicehidden=tablet&statTypehidden=oscombined®ionhidden=ZA&granularity=monthly&statType=Operating%20System®ion=South%20Africa&fromInt=202209&toInt=202309&fromMonthYear=2022-09&toMonthYear=2023-09&csv=1
The problem I have, is if I paste that link in any browser, I get a CSV download. If I access it with wget or curl, I get a bit of useless XML data.
I suspect they are detecting client type to stop people doing this.
I simply want to write a noscript that pulls down certain datasets, then processes that so I can store the final data in a specific folder on my Nextcloud server. I want to use it for internal use (decision-making), but I want the data to be updated each month automatically, rather than me sit and manually download it each month.
I know cURL is super powerful and flexible, so can someone explain to me how I would get cURL to tell the host server that it is Firefox or Chrome or whatever?
Edit:
The problem I had was caused by a really stupid but easy to make mistake.
I ran the following:
curl https://gs.statcounter.com/os-market-share/tablet/chart.php?device=Tablet&devicehidden=tablet&statTypehidden=oscombined®ionhidden=ZA&granularity=monthly&statType=Operating%20System®ion=South%20Africa&fromInt=202209&toInt=202309&fromMonthYear=2022-09&toMonthYear=2023-09&csv=1
That output the following:
1 11976
2 11977
3 11978
4 11979
5 11980
6 11981
7 11982
8 11983
9 11984
10 11985
11 11986
2 Done devicehidden=tablet
[3] Done statTypehidden=oscombined
[4] Done regionhidden=ZA
5 Done granularity=monthly
6 Done statType=Operating%20System
7 Done region=South%20Africa
8 Done fromInt=202209
9 Done toInt=202309
10- Done fromMonthYear=2022-09
<chart caption='StatCounter Global Stats' subCaption="Top 5 Desktop Browsers in from - , 1 Jan 1970" anchorAlpha='100' showValues='0' bgColor='FFFFFF' showalternatevgridcolor='0' showalternatehgridcolor='0' bgAlpha='0,0' numberSuffix='%' canvasBorderAlpha='50' bgImage='https://www.statcounter.com/images/logogschartfadedpadded.png' bgImageDisplayMode='fit' canvasBgAlpha='0'
exportEnabled='1' exportAtClient='0' exportAction='download' exportFormats='PNG' exportHandler='https://gs.statcounter.com/export/index.php' exportFileName='StatCounter-browser--all--'
legendBorderAlpha='0' legendBgColor='000000' legendBgAlpha='0' legendPosition='RIGHT' legendShadow='0'
canvasBorderThickness='1' canvasPadding='0' showBorder='0' labelDisplay='Rotate' slantLabels='1'><categories></categories><styles>
<definition>
<style name='myCaptionFont' type='font' size='14' bold='1' isHTML='1' topMargin='14' />
</definition>
<application>
<apply toObject='Caption' styles='myCaptionFont' />
</application>
<definition>
<style name='myLegendFont' type='font' size='11' color='000000' bold='0' isHTML='1' />
</definition>
<application>
<apply toObject='Legend' styles='myLegendFont' />
</application>
<definition>
<style name='myHTMLFont' type='font' isHTML='1' />
</definition>
<application>
<apply toObject='TOOLTIP' styles='myHTMLFont' />
</application>
</styles>
</chart>
I forgot to put quotes around the url.
I do this:
curl
"https://gs.statcounter.com/os-market-share/tablet/chart.php?device=Tablet&devicehidden=tablet&statTypehidden=oscombined®ionhidden=ZA&granularity=monthly&statType=Operating%20System®ion=South%20Africa&fromInt=202209&toInt=202309&fromMonthYear=2022-09&toMonthYear=2023-09&csv=1"
and then I get this:
"Date","Android","iOS","Unknown","Windows","Linux","Other"
2022-09,61.01,38.46,0.33,0.18,0.01,0
2022-10,59.53,40.21,0.15,0.09,0.02,0.01
2022-11,60.19,39.64,0.1,0.06,0.01,0
2022-12,59.12,40.73,0.1,0.04,0.01,0
2023-01,56.26,43.52,0.16,0.05,0.01,0
2023-02,57.23,42.55,0.12,0.08,0.01,0
2023-03,58.79,41.02,0.16,0,0.02,0
2023-04,58.72,40.99,0.28,0,0.02,0
2023-05,56.79,42.68,0.48,0,0.04,0
2023-06,60.21,39.1,0.67,0,0.02,0
2023-07,60.21,39.07,0.62,0,0.09,0
2023-08,60.1,39.14,0.72,0,0.03,0
2023-09,59.13,39.94,0.9,0,0.03,0.01
The lesson here is always use quotes. Make it a habit, or special characters will make things frustrating...
https://redd.it/17h2xpp
@r_bash
and then I get this:
"Date","Android","iOS","Unknown","Windows","Linux","Other"
2022-09,61.01,38.46,0.33,0.18,0.01,0
2022-10,59.53,40.21,0.15,0.09,0.02,0.01
2022-11,60.19,39.64,0.1,0.06,0.01,0
2022-12,59.12,40.73,0.1,0.04,0.01,0
2023-01,56.26,43.52,0.16,0.05,0.01,0
2023-02,57.23,42.55,0.12,0.08,0.01,0
2023-03,58.79,41.02,0.16,0,0.02,0
2023-04,58.72,40.99,0.28,0,0.02,0
2023-05,56.79,42.68,0.48,0,0.04,0
2023-06,60.21,39.1,0.67,0,0.02,0
2023-07,60.21,39.07,0.62,0,0.09,0
2023-08,60.1,39.14,0.72,0,0.03,0
2023-09,59.13,39.94,0.9,0,0.03,0.01
The lesson here is always use quotes. Make it a habit, or special characters will make things frustrating...
https://redd.it/17h2xpp
@r_bash
Flushing the read buffer, or something similar
Howdy, I've a tiny noscript which i've just updated to use inotifywait to block until a file is opened or closed, replacing a dumb periodic poll. Nice, like that. But the file is opened and closed a few times when it does, meaning when the access happens, the loop is executed (differently) a few times in a second or so. Is there any way I can purge the pending reads, and instead wait for a few seconds to let things settle and then see what's what?
inotifywait /dev/video? -e open,close -m | while read LINE
do
sleep 2 # wait for steady state
do_something_to_clear_any_backlog
lsof /dev/video? 2>&1 | grep -q zoom \
&& echo -e "\xA0\x01\x01\xA2" \
|| echo -e "\xA0\x01\x00\xA1"
done > /dev/ttyUSB1
TBH I guess I could just NOT use the -m and restart inotifywait each loop, but I'm mostly curious to know if there's a good solution this way.
\[BTW, as I think it's funny, this is a noscript that "puts on a red light" in another room when I'm on a zoom video call to stop my kids bugging me when I can't reply... so I called it "[roxanne.sh](https://roxanne.sh)" :D \]
https://redd.it/17hipg3
@r_bash
Howdy, I've a tiny noscript which i've just updated to use inotifywait to block until a file is opened or closed, replacing a dumb periodic poll. Nice, like that. But the file is opened and closed a few times when it does, meaning when the access happens, the loop is executed (differently) a few times in a second or so. Is there any way I can purge the pending reads, and instead wait for a few seconds to let things settle and then see what's what?
inotifywait /dev/video? -e open,close -m | while read LINE
do
sleep 2 # wait for steady state
do_something_to_clear_any_backlog
lsof /dev/video? 2>&1 | grep -q zoom \
&& echo -e "\xA0\x01\x01\xA2" \
|| echo -e "\xA0\x01\x00\xA1"
done > /dev/ttyUSB1
TBH I guess I could just NOT use the -m and restart inotifywait each loop, but I'm mostly curious to know if there's a good solution this way.
\[BTW, as I think it's funny, this is a noscript that "puts on a red light" in another room when I'm on a zoom video call to stop my kids bugging me when I can't reply... so I called it "[roxanne.sh](https://roxanne.sh)" :D \]
https://redd.it/17hipg3
@r_bash
is there any way I can only parse a single command line argument without bothering with others
I have a command that I want to wrap, it doesn't take an argument for output file but I want to wrap it in a function to achieve that, I'm trying to use `getopt` and `getopts` and both require that I know all the arguments I'm going to give to the command beforehand. for example: I have a function like this
wrapper_command () {
echo $(getopt "o:")
while getopts "o:" opt; do
case "${opt}" in
o) output=$OPTARG;;
esac
done
my_command $* > $output
}
then I invoke the command using `wrapper_command <args> -o outputfile` but `getopts` returns `--` for the output and `getopts` complains when the other arguments are not included in the optstring.
https://redd.it/17ht40g
@r_bash
I have a command that I want to wrap, it doesn't take an argument for output file but I want to wrap it in a function to achieve that, I'm trying to use `getopt` and `getopts` and both require that I know all the arguments I'm going to give to the command beforehand. for example: I have a function like this
wrapper_command () {
echo $(getopt "o:")
while getopts "o:" opt; do
case "${opt}" in
o) output=$OPTARG;;
esac
done
my_command $* > $output
}
then I invoke the command using `wrapper_command <args> -o outputfile` but `getopts` returns `--` for the output and `getopts` complains when the other arguments are not included in the optstring.
https://redd.it/17ht40g
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why is my terminal not redrawing the screen when I reach two lines of input?
https://imgur.com/a/hIsrUSy
Kitty is shown in the GIFs, but it just mirrors the output from bash. Here is entirety of my .bashrc configuration:
Commenting out the entire line doesn't fix the issue. Entering and exiting full-screen will properly refresh bash.
https://redd.it/17i3asu
@r_bash
https://imgur.com/a/hIsrUSy
Kitty is shown in the GIFs, but it just mirrors the output from bash. Here is entirety of my .bashrc configuration:
export PS1="\e[34m\] ∴ \e[32m\]\\u\e[31m\] \-> \e[33m\]\\W \e[37m\]$ "Commenting out the entire line doesn't fix the issue. Entering and exiting full-screen will properly refresh bash.
https://redd.it/17i3asu
@r_bash
Imgur
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users.