Performance repport generator noscript in bash
I'd like to know if someone can help me writing a noscript that collect data (memory, cpu, network) then put them in table which will contain the data chosen by the user, and an ascii graph related to the data chosen by the user.
I'm a student and I'm facing a lot of difficulties, I'd like it if someone could help me write this noscript.
(I have the document where everything is written but it's in french in someone may need it)
Many thanks
https://redd.it/1cv7qsr
@r_bash
I'd like to know if someone can help me writing a noscript that collect data (memory, cpu, network) then put them in table which will contain the data chosen by the user, and an ascii graph related to the data chosen by the user.
I'm a student and I'm facing a lot of difficulties, I'd like it if someone could help me write this noscript.
(I have the document where everything is written but it's in french in someone may need it)
Many thanks
https://redd.it/1cv7qsr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Chaining multiple grep commands to take in same input
How to chain two grep commands so that if the first grep fails, second grep attempts to find a match. To illustrate my problem, consider the following:
Ultimately I want to do a double grep on a piped stdin like so
I used echo just as an example. What I'm actually piping around is a multi-line output.
https://redd.it/1cvc1o4
@r_bash
How to chain two grep commands so that if the first grep fails, second grep attempts to find a match. To illustrate my problem, consider the following:
echo "360" | { grep 360 || echo "not found"; } Prints out the expected result "360"echo "360" | { grep 240 || echo "not found"; } Prints out the expected result "not found"echo "360" | { grep 360 || grep 240; } Prints out the expected result "360"echo "360" | { grep 240 || grep 360; } Prints an empty line instead of doing another grep and printing out "360"Ultimately I want to do a double grep on a piped stdin like so
echo "hurrdurr" | { grep 360 || grep 240 || echo "not found"; } But the two grep commands not ORing correctly is messing my commandI used echo just as an example. What I'm actually piping around is a multi-line output.
mycommand | { grep needle1 || grep needle2 || grep needle3 || echo "not found"; }https://redd.it/1cvc1o4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
using qpdf: could I delete last (inblank) page?
Hi, I'd like to delete last sheet, last page of a pdf, Is there a command for it in qpdf?
Thank you?
https://redd.it/1cvxnx0
@r_bash
Hi, I'd like to delete last sheet, last page of a pdf, Is there a command for it in qpdf?
Thank you?
https://redd.it/1cvxnx0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Could someone explain the logic behind a find command which renames files for me?
I have the following command which I use from time to time (via Google):
find /the/path -depth -name "*.abc" -exec sh -c 'mv "$1" "${1%.abc}.edefg"' _ {} \;
I know that it works, and I know that I need the underscore and the curly brackets at the end before the escaped ;. Without them, the command ends up only giving the extension.
*Why* are the underscore and the curly brackets needed? What exactly do they do in this context? The `bash -c` command takes the `{}` as the argument to give you `$1`, but where does the underscore fit in?
If you have a link to where this is explained, it would be great.
https://redd.it/1cw9iuo
@r_bash
I have the following command which I use from time to time (via Google):
find /the/path -depth -name "*.abc" -exec sh -c 'mv "$1" "${1%.abc}.edefg"' _ {} \;
I know that it works, and I know that I need the underscore and the curly brackets at the end before the escaped ;. Without them, the command ends up only giving the extension.
*Why* are the underscore and the curly brackets needed? What exactly do they do in this context? The `bash -c` command takes the `{}` as the argument to give you `$1`, but where does the underscore fit in?
If you have a link to where this is explained, it would be great.
https://redd.it/1cw9iuo
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Complete noob having issue with strange url in terminal
Hi my dudes,
I try to avoid the terminal as much as I can, but sometimes you're just forced to build or run some command line application. E.g., I would like to run the following command to convert an iso to chd:
This does, in fact, work as intended. However, when I look at the terminal output, I notice the following:
I honestly have no clue what this is supposed to signify. I suppose some odd custom ssl connection setting or something? Scantailor Advanced is a program I did install at some point, but how is it that anytime I use
Hope someone can advise on this, would be much appreciated!
https://redd.it/1cwg3vp
@r_bash
Hi my dudes,
I try to avoid the terminal as much as I can, but sometimes you're just forced to build or run some command line application. E.g., I would like to run the following command to convert an iso to chd:
#!/bin/bashfor file in *.iso; do chdman createcd -i "${file%.*}.iso" -o "${file%.*}.chd"; doneThis does, in fact, work as intended. However, when I look at the terminal output, I notice the following:
#/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yb85/scantailor-advanced-osx/HEAD/install.sh)"I honestly have no clue what this is supposed to signify. I suppose some odd custom ssl connection setting or something? Scantailor Advanced is a program I did install at some point, but how is it that anytime I use
#!/bin/bash I am presented with this url of a program I am not even working with in that moment? It seems to me this is not how things should be setup. Thus, my question, how can I restore this for it to just work normally without this url being involved in anything?Hope someone can advise on this, would be much appreciated!
https://redd.it/1cwg3vp
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can anybody help me to write this bash noscript?
I have found this command to compress PDF files and it works. But it is too long for me to memorize it.
I want to make a bash noscript like this:
So if it is a simple question, sorry. I've been using linux for about 5 months.
https://redd.it/1cx25bg
@r_bash
I have found this command to compress PDF files and it works. But it is too long for me to memorize it.
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_PDF_file.pdf input_PDF_file.pdfI want to make a bash noscript like this:
compress input.pdf output.pdfSo if it is a simple question, sorry. I've been using linux for about 5 months.
https://redd.it/1cx25bg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Code review request for a recent noscript I made to simplify the progress of setup a SSH SOCKS service
Code: https://gitlab.com/brlin/ProxifierLinux/-/blob/main/enable-ssh-socks-service.sh
Refer the write up for the utilization of this noscript: How to force Steam access the internet via a proxy service in GNU/Linux? - HackMD
https://redd.it/1cx52rv
@r_bash
Code: https://gitlab.com/brlin/ProxifierLinux/-/blob/main/enable-ssh-socks-service.sh
Refer the write up for the utilization of this noscript: How to force Steam access the internet via a proxy service in GNU/Linux? - HackMD
https://redd.it/1cx52rv
@r_bash
GitLab
enable-ssh-socks-service.sh · main · 林博仁 Buo-ren, Lin / ProxifierLinux · GitLab
Proxifier alternative for linux using redsocks. Proxify all linux applications through SOCKS4/5, HTTP proxy
use variable in variable while looping
Hi,
In a larger noscript I need to loop through a list of predefined items. Underneath a simplified working part of the noscript:
#!/bin/bash
totalitems=4
# define integers
item[1]=40
item[2]=50
item[3]=45
item[4]=33
# start with first
counter=1
while [ "$counter" -le "$totalitems" ]
do
echo "${item$counter}"
let counter+=1
done
However I'm curious if the same is possible without using an array. Is it even possible to combine the variables 'item' and 'counter', e.g.:
#!/bin/bash
totalitems=4
# define integers
item1=40
item2=50
item3=45
item4=33
# start with first
counter=1
while [ "$counter" -le "$totalitems" ]
do
echo "$item$counter" <---
let counter+=1
done
https://redd.it/1cx6iqw
@r_bash
Hi,
In a larger noscript I need to loop through a list of predefined items. Underneath a simplified working part of the noscript:
#!/bin/bash
totalitems=4
# define integers
item[1]=40
item[2]=50
item[3]=45
item[4]=33
# start with first
counter=1
while [ "$counter" -le "$totalitems" ]
do
echo "${item$counter}"
let counter+=1
done
However I'm curious if the same is possible without using an array. Is it even possible to combine the variables 'item' and 'counter', e.g.:
#!/bin/bash
totalitems=4
# define integers
item1=40
item2=50
item3=45
item4=33
# start with first
counter=1
while [ "$counter" -le "$totalitems" ]
do
echo "$item$counter" <---
let counter+=1
done
https://redd.it/1cx6iqw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
why in the server where I upload dirs and files I can not do mkdir -p dir1 dir1/subdir1/ dir1/subdir2/ etc?
Hi. will there be bash in the server? the server mean place where I use sftp user@server.team
in local I can do mkdir flag -p ...
Thank you and regards!
https://redd.it/1cxdscs
@r_bash
Hi. will there be bash in the server? the server mean place where I use sftp user@server.team
in local I can do mkdir flag -p ...
Thank you and regards!
https://redd.it/1cxdscs
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
TIL: Prompt in "read -p prompt" goes to stderr
It is documented in
>\-p prompt
>
>Display prompt on standard error, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.
but not in
>\-p prompt
>
>output the string PROMPT without a trailing newline before attempting to read
So,
https://redd.it/1cxkocc
@r_bash
It is documented in
man bash:>\-p prompt
>
>Display prompt on standard error, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.
but not in
help read:>\-p prompt
>
>output the string PROMPT without a trailing newline before attempting to read
So,
echo -n prompt; read is NOT equivalent to read -p prompt. The former should be preferred, because you're free to send the prompt to either stdout or stderr without side effects. Even though read -p prompt 2>&1 would send the prompt to stdout, error messages produced by read would go there as well.https://redd.it/1cxkocc
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Ffmpeg, ranger & concatenating
I've been using these noscripts with mpv for years which makes it simple to chop up, crop & encode video from from mpv. add in a file delete noscript and I can chop up, crop & encode video, and delete the original from mpv just using the keyboard, which is nice.
what they don't allow me to do is stitch video back together, like this.
I use ranger to launch mpv and would be nice if I can use that to concatenate.
I currently have this in my rc.conf:
it kinda works a bit but feels janky, I need to delete files and rename stuff, and have no idea what I am doing when it comes to noscripting stuff.
ideally I would select %s files as I do with the space bar on ranger, be able to specify the output file name and not have to worry about duplicate mylist.txt files.
any ideas?
is this the right place for this kinda question? I'm new here
https://redd.it/1cxmx7y
@r_bash
I've been using these noscripts with mpv for years which makes it simple to chop up, crop & encode video from from mpv. add in a file delete noscript and I can chop up, crop & encode video, and delete the original from mpv just using the keyboard, which is nice.
what they don't allow me to do is stitch video back together, like this.
I use ranger to launch mpv and would be nice if I can use that to concatenate.
I currently have this in my rc.conf:
map xc shell for f in %s ; do echo "file $f'" >> mylist.txt; donemap xj shell ffmpeg -f concat -safe 0 -i mylist.txt -c copy complete.mp4it kinda works a bit but feels janky, I need to delete files and rename stuff, and have no idea what I am doing when it comes to noscripting stuff.
ideally I would select %s files as I do with the space bar on ranger, be able to specify the output file name and not have to worry about duplicate mylist.txt files.
any ideas?
is this the right place for this kinda question? I'm new here
https://redd.it/1cxmx7y
@r_bash
GitHub
GitHub - occivink/mpv-noscripts: Various noscripts for mpv
Various noscripts for mpv. Contribute to occivink/mpv-noscripts development by creating an account on GitHub.
ifempty: data protection wrapper for mkfs.X tools
When you try to format some non-empty storage with mkfs.ext4, it asks for a confirmation:
> truncate -s 100m 1.img
> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 25600 4k blocks and 25600 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
1.img contains a ext4 file system
created on Wed May 22 02:13:10 2024
Proceed anyway? (y,N) n
Not all mkfs tools act like that. For example, mkfs.fat (and aliases mkfs.msdos, mkfs.vfat), mkfs.exfat, mkfs.udf, mkfs.ntfs, mkfs.minix just format everything without any checks.
My noscript can be used to add the non-empty check to such "dumb" tools. There is a detailed README in the repo
https://github.com/slowpeek/ifempty
https://redd.it/1cxlwkf
@r_bash
When you try to format some non-empty storage with mkfs.ext4, it asks for a confirmation:
> truncate -s 100m 1.img
> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 25600 4k blocks and 25600 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
1.img contains a ext4 file system
created on Wed May 22 02:13:10 2024
Proceed anyway? (y,N) n
Not all mkfs tools act like that. For example, mkfs.fat (and aliases mkfs.msdos, mkfs.vfat), mkfs.exfat, mkfs.udf, mkfs.ntfs, mkfs.minix just format everything without any checks.
My noscript can be used to add the non-empty check to such "dumb" tools. There is a detailed README in the repo
https://github.com/slowpeek/ifempty
https://redd.it/1cxlwkf
@r_bash
GitHub
GitHub - slowpeek/ifempty: Data protection wrapper for mkfs.X tools
Data protection wrapper for mkfs.X tools. Contribute to slowpeek/ifempty development by creating an account on GitHub.
Whenever I run the 'find' command, it seems to replace Chinese characters with "?" marks. The 'ls' command does not do this. How do I get 'find' to behave?
Meanwhile,
What gives?
https://redd.it/1cxq2ci
@r_bash
user@server$ find . -type f...????????????????? www.HDBTHD.com???????????????[???????????????].Stargate.1994.1080p.BluRay.x265.10bit.DTS.mkv...Meanwhile,
ls correctly gives me: 【高清影视之家发布 www.HDBTHD.com】星际之门[简繁英字幕].Stargate.1994.1080p.BluRay.x265.10bit.DTS.mkv.What gives?
https://redd.it/1cxq2ci
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Starship Prompt showing vertical line in the prompt graphic.
I recently started using Starship to configure my bash prompt. One thing I noticed are these vertical lines that appear when the shape of the prompt graphic changes. I have a slight orange line where it changes to a point and a slight blue line when it changes to a half circle. Is there a way to fix this?
https://preview.redd.it/frbwxp0vd12d1.png?width=291&format=png&auto=webp&s=af37adcc3788d62ff210fc3a3de4f77e00b5e418
https://redd.it/1cya8tt
@r_bash
I recently started using Starship to configure my bash prompt. One thing I noticed are these vertical lines that appear when the shape of the prompt graphic changes. I have a slight orange line where it changes to a point and a slight blue line when it changes to a half circle. Is there a way to fix this?
https://preview.redd.it/frbwxp0vd12d1.png?width=291&format=png&auto=webp&s=af37adcc3788d62ff210fc3a3de4f77e00b5e418
https://redd.it/1cya8tt
@r_bash
is there a shortcut for jump to start of a command and other for jump to end of the same command?
Hi!. sometimes I wrote long command for 4 lines and repeat the command and I' d like to know if there is a shorcut for move the prompt to start of the command.
for example:
~/path/$ montage * -tile 3x2 -shadow -geometry 200x200+5+5 -noscript '\nEmisiones del día miércoles 22 Mayo 2024\nentre 01 y 04:30hs.\nE.E.G. cada 7 minutos y de 30 seg. de duración.\nModerado Humo y moderado Olor\nEn aumento con el paso de las horas' -pointsize 12 -set label '%f\n%wx%hpx\n%[exif:DateTime]hs' -quality 90 ../catalogo3.jpg
Thank you and Regards!
https://redd.it/1cye9mu
@r_bash
Hi!. sometimes I wrote long command for 4 lines and repeat the command and I' d like to know if there is a shorcut for move the prompt to start of the command.
for example:
~/path/$ montage * -tile 3x2 -shadow -geometry 200x200+5+5 -noscript '\nEmisiones del día miércoles 22 Mayo 2024\nentre 01 y 04:30hs.\nE.E.G. cada 7 minutos y de 30 seg. de duración.\nModerado Humo y moderado Olor\nEn aumento con el paso de las horas' -pointsize 12 -set label '%f\n%wx%hpx\n%[exif:DateTime]hs' -quality 90 ../catalogo3.jpg
Thank you and Regards!
https://redd.it/1cye9mu
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Could someone explain this behaviour?
> bash -c 'ls -l "$1"; sudo ls -l "$1"' - <(echo abc)
lr-x------ 1 pcowner pcowner 64 May 24 02:36 /dev/fd/63 -> 'pipe:679883'
ls: cannot access '/dev/fd/63': No such file or directory
https://redd.it/1cz734d
@r_bash
> bash -c 'ls -l "$1"; sudo ls -l "$1"' - <(echo abc)
lr-x------ 1 pcowner pcowner 64 May 24 02:36 /dev/fd/63 -> 'pipe:679883'
ls: cannot access '/dev/fd/63': No such file or directory
https://redd.it/1cz734d
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
is there a difference between "ctrl /" and "ctrl shift -" ?
hello, i'm trying to learn the keyboard shortcuts for bash, and i was learning about how to undo something i did in the terminal text line and i heard about
"ctrl /" which undoes something you did in your text line
then i heard about
"ctrl shift -" which ALSO undoes something you did in the text line apparently
is there any difference between the two keyboard shortcuts? or are they both the same?
thank you
https://redd.it/1czgu8h
@r_bash
hello, i'm trying to learn the keyboard shortcuts for bash, and i was learning about how to undo something i did in the terminal text line and i heard about
"ctrl /" which undoes something you did in your text line
then i heard about
"ctrl shift -" which ALSO undoes something you did in the text line apparently
is there any difference between the two keyboard shortcuts? or are they both the same?
thank you
https://redd.it/1czgu8h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
BASH syntax help
Hi folks.
I am struggling with my BASH syntax. I am trying translate some commands from the cli, in to a noscript. I am capturing input variables, to be used within an array, however for the life of me I cannot figure out where I am messing up.
Here is the cmd, from the cli:-
`grep -E $"date"\|HTTP/[0-9]*\.[0-9]+\"\s$status' *`
Here is the noscript, in which I began using two greps, as doing it like the above, using `'pattern1\|pattern2'` didn't work, even on the cli:-
1 #!/bin/env bash
2
3
4
5 echo Please enter the day, month, year and time you wish to search \(eg:- 6 12/Nov/2023:13:24 or 12/Nov/2023:01:24\) [Enter]:
6 read date
7
8 echo Please enter the http status code you wish to search \(eg:- 200\) [Enter]:
9 read status
10
11 echo Please enter the server name you wish to search \(eg:- SERVER.DOMAIN\) [Enter]:
12 read server
13
14 search="$(grep -a '$date' log-file-2024* > /tmp/first.txt && grep -a 'HTTP/1.0" "$status" first.txt > /tmp/"$server"_access_logs.txt)"
15
16 ssh user@"$server" cd /SOME/RANDOM/DIR; timeout -k 2 20 "$search"
The error I receive when running `bash -x` [`noscript.sh`](http://noscript.sh):-
`noscript.sh: line 14: first.txt > /tmp/first.txt: No such file or directory`
... then my ssh command sits idle, without having any variables successfully added, like so:-
`+ ssh user@ cd /some/random/directory`
I have tried various approaches to my variables, but I can never get them to be called, correctly.
https://redd.it/1czm64i
@r_bash
Hi folks.
I am struggling with my BASH syntax. I am trying translate some commands from the cli, in to a noscript. I am capturing input variables, to be used within an array, however for the life of me I cannot figure out where I am messing up.
Here is the cmd, from the cli:-
`grep -E $"date"\|HTTP/[0-9]*\.[0-9]+\"\s$status' *`
Here is the noscript, in which I began using two greps, as doing it like the above, using `'pattern1\|pattern2'` didn't work, even on the cli:-
1 #!/bin/env bash
2
3
4
5 echo Please enter the day, month, year and time you wish to search \(eg:- 6 12/Nov/2023:13:24 or 12/Nov/2023:01:24\) [Enter]:
6 read date
7
8 echo Please enter the http status code you wish to search \(eg:- 200\) [Enter]:
9 read status
10
11 echo Please enter the server name you wish to search \(eg:- SERVER.DOMAIN\) [Enter]:
12 read server
13
14 search="$(grep -a '$date' log-file-2024* > /tmp/first.txt && grep -a 'HTTP/1.0" "$status" first.txt > /tmp/"$server"_access_logs.txt)"
15
16 ssh user@"$server" cd /SOME/RANDOM/DIR; timeout -k 2 20 "$search"
The error I receive when running `bash -x` [`noscript.sh`](http://noscript.sh):-
`noscript.sh: line 14: first.txt > /tmp/first.txt: No such file or directory`
... then my ssh command sits idle, without having any variables successfully added, like so:-
`+ ssh user@ cd /some/random/directory`
I have tried various approaches to my variables, but I can never get them to be called, correctly.
https://redd.it/1czm64i
@r_bash
how to bash noscript output to vim
So I created a custom bash noscript echos some question to read input from user for configuration purpose and later echo $(pwd)/filename.sh. When the noscript outputs the path + filename, I would like to open vim with the output. I tried pipe the output to vim input, but somehow the bash noscript doesn't appear to echoing anything to read input. Anyone wanna give me some idea how and why? For now, my assumption is that when noscript is executed where both echo and read is operated, echo is redirected to vim (which why any echo from noscript doesn't show output on terminal) and read waits for my input. If I can redirect the echo back to the terminal, then the expression works as expected. But I do not know how. Maybe I need to use either `>` or `>>` to redirect `echo` output to shell?
`$ noscript-gen.sh | xargs vim # failed`
https://redd.it/1czta63
@r_bash
So I created a custom bash noscript echos some question to read input from user for configuration purpose and later echo $(pwd)/filename.sh. When the noscript outputs the path + filename, I would like to open vim with the output. I tried pipe the output to vim input, but somehow the bash noscript doesn't appear to echoing anything to read input. Anyone wanna give me some idea how and why? For now, my assumption is that when noscript is executed where both echo and read is operated, echo is redirected to vim (which why any echo from noscript doesn't show output on terminal) and read waits for my input. If I can redirect the echo back to the terminal, then the expression works as expected. But I do not know how. Maybe I need to use either `>` or `>>` to redirect `echo` output to shell?
`$ noscript-gen.sh | xargs vim # failed`
https://redd.it/1czta63
@r_bash