was this a good case for automation
i had a task today - change old license agreement in 500 files in git repo. The problem was that there was no single template for license agrmt, various devs and teams wrote templates in all kinds of ways - short(4 lines) and long ( 20-50 lines) in several formats
here are templates, even varied by year:
template 3:
/*
*
*
*2020 company_name.
* All Rights Reserved
* Copyright (C)
*
*
* NOTICE: All information contained herein is, and remains
* the property of company_name and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to company_name and its suppliers
* and may be covered by U.S. and Foreign Patents, patents in
* process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from company_name.
*
*
/
i cloned the repo
asked ai to write prompt to catch the files and remove the text using while loop + sed
and it did not work, then i just manually found all different templates based on "Copyright company_name" or variation of that and removed under 15 min ))
should i have done all the effort to write perfect bash noscript or i did it manually and it was good?
https://redd.it/1j0repw
@r_bash
i had a task today - change old license agreement in 500 files in git repo. The problem was that there was no single template for license agrmt, various devs and teams wrote templates in all kinds of ways - short(4 lines) and long ( 20-50 lines) in several formats
here are templates, even varied by year:
/** Copyright (C) 2020 COMPANY NAME* All Rights Reserved*/typical long full license header:-- /*-- * NOTICE: All information contained herein is, and remains-- * the property of company_name and its suppliers,-- * if any. The intellectual and technical concepts contained-- * herein are proprietary to company_name and its suppliers-- * and may be covered by U.S. and Foreign Patents, patents in-- * process, and are protected by trade secret or copyright law.-- /*template 2:/***** copyright (c) company name* All Rights Reserved*** NOTICE: All information contained herein is, and remains* the property of company_name and its suppliers,* if any. The intellectual and technical concepts contained* bla bla bla* bla bla bla* bla bla bla* from company_name.*/*/** company (c) 2019 company name* all rights reserved**//** company (c) 2020 company name* all rights reserved**/template 3:
/*
*
*
*2020 company_name.
* All Rights Reserved
* Copyright (C)
*
*
* NOTICE: All information contained herein is, and remains
* the property of company_name and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to company_name and its suppliers
* and may be covered by U.S. and Foreign Patents, patents in
* process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from company_name.
*
*
/
i cloned the repo
asked ai to write prompt to catch the files and remove the text using while loop + sed
and it did not work, then i just manually found all different templates based on "Copyright company_name" or variation of that and removed under 15 min ))
should i have done all the effort to write perfect bash noscript or i did it manually and it was good?
https://redd.it/1j0repw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can it be both Link and Directory?
/bin/bash --version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu)
$ cat test1.sh
#!/bin/bash
mkdir -p dir
ln -sf dir link2dir
test -d dir && echo "dir is Directroy."
test -h link2dir && echo "link2dir is link"
test -d link2dir && echo "link2dir is Directroy"
$ ./test1.sh
dir is Directroy.
link2dir is link
link2dir is Directroy
https://redd.it/1j10hbg
@r_bash
/bin/bash --version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu)
$ cat test1.sh
#!/bin/bash
mkdir -p dir
ln -sf dir link2dir
test -d dir && echo "dir is Directroy."
test -h link2dir && echo "link2dir is link"
test -d link2dir && echo "link2dir is Directroy"
$ ./test1.sh
dir is Directroy.
link2dir is link
link2dir is Directroy
https://redd.it/1j10hbg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Running a periodic copy noscript. Using cp -n because I don't want recursion. Get error as a result.
I have a noscript running that periodically sweeps a bunch of sftp uploads from branch offices. Each office has a /bleh/sftp/OfficeName/ dir, and an /bleh/sftp/OfficeName/upload/ subdir where files are uploaded to them. I don't need or want those copied back to where I'm processing these other files they've uploaded back to me, so I use the command
cp -n /bleh/sftp/OfficeName/ /opt/crunchfiles/officecode/
Which gives the desired result, omitting the contents of the upload/ subdir. However, I receive the output:
cp: -r not specified, omitting directory '/bleh/sftp/OfficeName/upload'
To which I have taken to replying "NO SHIT! That's what you are supposed to be doing, it's not an error or misconfiguration, it's an intentional use of switches to get the result I want!"
Redirecting the output to /dev/null as in
cp -n /bleh/sftp/OfficeName/ /opt/crunchfiles/officecode/ 2>/dev/null
works to suppress the message, but the noscript still exists with error code 1, which means it still shows up as a failure in my orchestrator. How can I avoid the error code and tell it to just copy the files specified by the switches and stop messing me up with my metrics?
https://redd.it/1iyt79j
@r_bash
I have a noscript running that periodically sweeps a bunch of sftp uploads from branch offices. Each office has a /bleh/sftp/OfficeName/ dir, and an /bleh/sftp/OfficeName/upload/ subdir where files are uploaded to them. I don't need or want those copied back to where I'm processing these other files they've uploaded back to me, so I use the command
cp -n /bleh/sftp/OfficeName/ /opt/crunchfiles/officecode/
Which gives the desired result, omitting the contents of the upload/ subdir. However, I receive the output:
cp: -r not specified, omitting directory '/bleh/sftp/OfficeName/upload'
To which I have taken to replying "NO SHIT! That's what you are supposed to be doing, it's not an error or misconfiguration, it's an intentional use of switches to get the result I want!"
Redirecting the output to /dev/null as in
cp -n /bleh/sftp/OfficeName/ /opt/crunchfiles/officecode/ 2>/dev/null
works to suppress the message, but the noscript still exists with error code 1, which means it still shows up as a failure in my orchestrator. How can I avoid the error code and tell it to just copy the files specified by the switches and stop messing me up with my metrics?
https://redd.it/1iyt79j
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
FUNCNAME array with some empty values
Hi,
I'd like to print an error message displaying the call stack from a specific function that is passed an error message, the specific function having to display the call stack plus the error message
I thought I could use FUNCNAME array within that function
Strangely though, FUNCNAME array has 20 values, the 16th last being empty ...
Thus I can't use FUNCNAME length to determine the main noscript filename that would be ${BASH_SOURCE[${#FUNCNAME}-1\]} and output the names in FUNCNAME array from first to penultimate value.
Of course, it's possible to get the last index which value is not empty, but I'd like to understand why FUNCNAME lists those empty values.
Thanks for your help !
https://redd.it/1j23zsk
@r_bash
Hi,
I'd like to print an error message displaying the call stack from a specific function that is passed an error message, the specific function having to display the call stack plus the error message
I thought I could use FUNCNAME array within that function
Strangely though, FUNCNAME array has 20 values, the 16th last being empty ...
Thus I can't use FUNCNAME length to determine the main noscript filename that would be ${BASH_SOURCE[${#FUNCNAME}-1\]} and output the names in FUNCNAME array from first to penultimate value.
Of course, it's possible to get the last index which value is not empty, but I'd like to understand why FUNCNAME lists those empty values.
Thanks for your help !
https://redd.it/1j23zsk
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Notifications in the terminal
Hello, I wanted to make a command that would print out desktop notifications in the terminal, by using tail -f on the notification log file.
>
works as intended, i get the response:
>
>
>
>
>
>
But when i add awk, to only print out the content after the equals sign I get no response. The command is running but it's returning nothing.
>
with set -x I get:
>
>
>
I tried making a noscript with a while expression instead of awk, again no output.
>
>
>
>
>
>
>
I honestly don't understand where the issue is. Any help is much appreciated.
https://redd.it/1j1z23q
@r_bash
Hello, I wanted to make a command that would print out desktop notifications in the terminal, by using tail -f on the notification log file.
>
tail -f /home/user/.cache/xfce4/notifyd/log | grep -E "app_name|summary|body"works as intended, i get the response:
>
app_name=notify-send>
summary=1234>
body=>
app_name=notify-send>
summary=test2>
body=But when i add awk, to only print out the content after the equals sign I get no response. The command is running but it's returning nothing.
>
tail -f /home/user/.cache/xfce4/notifyd/log | grep -E "app_name|summary|body" | awk -F'=' '{print $2}'with set -x I get:
>
+ tail -f /home/user/.cache/xfce4/notifyd/log>
+ grep -E 'app_name|summary|body'>
+ awk -F= '{print $2}'I tried making a noscript with a while expression instead of awk, again no output.
>
#!/bin/bash>
# Path to the log file>
LOG_FILE="/home/user/.cache/xfce4/notifyd/log">
# Tail the log file, filter lines, and extract content after the equals sign>
tail -f "$LOG_FILE" | grep -E "app_name|summary|body" | while IFS='=' read -r key value; do>
echo "$value">
doneI honestly don't understand where the issue is. Any help is much appreciated.
https://redd.it/1j1z23q
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
what did I do wrong
\#!/bin/bash
[ttjz8b@delmar \~\]$ echo Name,phoneNumber,Expense1,Expense2,Expense3 > move1.csv
[ttjz8b@delmar \~\]$ cat data.csv >> move1.csv
[ttjz8b@delmar \~\]$ grep "\^S.*r," data.csv | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move2.txt
[ttjz8b@delmar \~\]$ grep "(777)" data.csv | sed 's/.* \\([\^,\]*\\),.*/\\1/' > move3.txt
[ttjz8b@delmar \~\]$ grep ",.* [ES\]" data.csv | sed 's/\\([\^ \]*\\) .*/\\1/' > move4.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move5.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\}$' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt
[ttjz8b@delmar \~\]$ sort -u move5.txt -o move5.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^A[A-Z\]* ,' | sed 's/,.*//' > move6.txt
[ttjz8b@delmar \~\]$
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^E[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^I[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^O[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv| grep '\^U[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ sort -u move6.txt -o move6.txt
[ttjz8b@delmar \~\]$ tail -n +2 move1.csv | perl -F',' -lane '($a,$b,$c)=map{s/\\$//;$_}@F[2,3,4\]; $max = $a>$b ? ($a>$c?$a:$c) : ($b>$c?$b:$c); printf "%s,\\$%.2f\\n", $F[0\], $max;' > move7.txt
[ttjz8b@delmar \~\]$ chmod +x transform.sh
[ttjz8b@delmar \~\]$ /transform.sh data.csv
\-bash: /transform.sh: No such file or directory
[ttjz8b@delmar \~\]$ ls
1 info.shmove2.txt move5.txt move.txt output
data.csv move1.csv move3.txt move6.txt multiline.txt transform.sh
file.csv move1.cv move4.txt move7.txt number where
[ttjz8b@delmar \~\]$ /transform.sh data.csv
\-bash: /transform.sh: No such file or directory. what did I do wrong
https://redd.it/1j1slc4
@r_bash
\#!/bin/bash
[ttjz8b@delmar \~\]$ echo Name,phoneNumber,Expense1,Expense2,Expense3 > move1.csv
[ttjz8b@delmar \~\]$ cat data.csv >> move1.csv
[ttjz8b@delmar \~\]$ grep "\^S.*r," data.csv | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move2.txt
[ttjz8b@delmar \~\]$ grep "(777)" data.csv | sed 's/.* \\([\^,\]*\\),.*/\\1/' > move3.txt
[ttjz8b@delmar \~\]$ grep ",.* [ES\]" data.csv | sed 's/\\([\^ \]*\\) .*/\\1/' > move4.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move5.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt
[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\}$' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt
[ttjz8b@delmar \~\]$ sort -u move5.txt -o move5.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^A[A-Z\]* ,' | sed 's/,.*//' > move6.txt
[ttjz8b@delmar \~\]$
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^E[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^I[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^O[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv| grep '\^U[A-Z\]* ,' | sed 's/,.*//' >> move6.txt
[ttjz8b@delmar \~\]$ sort -u move6.txt -o move6.txt
[ttjz8b@delmar \~\]$ tail -n +2 move1.csv | perl -F',' -lane '($a,$b,$c)=map{s/\\$//;$_}@F[2,3,4\]; $max = $a>$b ? ($a>$c?$a:$c) : ($b>$c?$b:$c); printf "%s,\\$%.2f\\n", $F[0\], $max;' > move7.txt
[ttjz8b@delmar \~\]$ chmod +x transform.sh
[ttjz8b@delmar \~\]$ /transform.sh data.csv
\-bash: /transform.sh: No such file or directory
[ttjz8b@delmar \~\]$ ls
1 info.shmove2.txt move5.txt move.txt output
data.csv move1.csv move3.txt move6.txt multiline.txt transform.sh
file.csv move1.cv move4.txt move7.txt number where
[ttjz8b@delmar \~\]$ /transform.sh data.csv
\-bash: /transform.sh: No such file or directory. what did I do wrong
https://redd.it/1j1slc4
@r_bash
Variable populated by docker command acts odd
I would just like to understand why this occurs.
I am running a command on docker containers to get their network id:
If I print out the var
As an example:
You get this result:
The way I found to solve this was to strip whatever is non-numerical
It works, but I'd still like to know what the heck is going on with the output. It should just be a numerical value
https://redd.it/1j2uykt
@r_bash
I would just like to understand why this occurs.
I am running a command on docker containers to get their network id:
iflink=$(docker exec -it "$container" bash -c 'cat /sys/class/net/eth0/iflink')
If I print out the var
iflink, it is indeed populated, but it appears that if you try to print anything AFTER the variable, it strips characters after, and the order is weird.As an example:
iflink=$(docker exec -it "$container" bash -c 'cat /sys/class/net/eth0/iflink')
echo "BEFORE........-${iflink}-...........AFTER"
You get this result:
# Expected
BEFORE........-1874-...........AFTER
BEFORE........-131876-...........AFTER
# Results
-...........AFTER1874
-...........AFTER^X131876
The way I found to solve this was to strip whatever is non-numerical
iflink=$(echo $iflink | sed 's/[^0-9]*//g' )
It works, but I'd still like to know what the heck is going on with the output. It should just be a numerical value
https://redd.it/1j2uykt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash not substituting variables on TAB, Macos; does on Debian
Hi!
I'm running Bash 5.2.37 on both my Debian box and my work's laptop, a Mac.
If I try to expand a variable value using Tab when using commands such as
There are no completion files for the above commands in any of the computers.
Running
(Not exactly true; the
How can I solve this? My main reason of exporting variables is to autocomplete them when needed.
Thanks!
https://redd.it/1j2un1v
@r_bash
Hi!
I'm running Bash 5.2.37 on both my Debian box and my work's laptop, a Mac.
If I try to expand a variable value using Tab when using commands such as
ls, Macos doesn't let me but Debian does. Whenever I try to expand a Bash variable by pressing Tab in ls $HO, I get a bell on Macos but I can do it on Debian; the expected behaviour is that I either get the expansion of $HOME (literally, with the $), or a list of suggestion with all of the variables that begin with that string. I have observed that this happens also with cp and mv, but not with user-defined functions or Macos commands such as open. There are no completion files for the above commands in any of the computers.
Running
shopt | awk '$2 == on {print $1}' on both machines returns the same activated options:autocd
checkwinsize
cmdhist
complete_fullquote
direxpand
expand_aliases
extglob
extquote
force_fignore
globasciiranges
globskipdots
interactive_comments
patsub_replacement
progcomp
promptvars
sourcepath
(Not exactly true; the
login_shell option is enabled on Macos for virtual terminals)How can I solve this? My main reason of exporting variables is to autocomplete them when needed.
Thanks!
https://redd.it/1j2un1v
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Named coprocesses, additional ones aren't enumerating their file denoscriptors.
So, I have my docker container in which I want to run my native binaries. Let's say I have
declare -r PROJECT='widget'
declare -ra MOCKS=(gadget what-sit) # thing-ama-jig)
in a file called project.sh, and when another noscriptlet called session.sh where I source that in, and then I loop over MOCKS to launch all of the programs:
for mock in ${MOCK@}; do
echo "Executing coprocess '${PROJECT}-${mock}/cmake-build-mock/${PROJECT}-${mock}.elf ${@}' as ${mock//[:punct:]/}"
coproc "${mock//[[:punct:]]/}" { ${PROJECT}-${mock}/cmake-build-mock/${PROJECT}-${mock}.elf "${@}"; }
# Plug co-process "${mock//[:punct:]/}" into the command-line interface.
done
And for the first mock program, `gadget`, it's working great. All of my mock programs are sitting out there, pretty as you please, I just need to get them all executing as named coprocs and then I can work on stitching together all of the file denoscriptors into something that makes sense.
$ . session.sh can0
Executing coprocess 'widget-gadget/cmake-build-mock/widget-gadget.elf can0' as gadget
Executing coprocess 'widget-what-sit/cmake-build-mock/widget-what-sit.elf can0' as whatsit
bash: warning: executecoproc: coproc [4:gadget] still exists
session.sh: line 14: widget-gadget/cmake-build-mock/widget-gadget.elf: cannot execute: required file not found
Well, it was working for the first mock program. Now, it's not. I was able to confirm the coprocesses were running with:
$ ps aux
...
root 6 99.5 0.0 3376 1720 pts/0 R 20:59 6:37 widget-gadget/cmake-build-mock/widget-gadget.elf can0
root 8 99.5 0.0 3376 1720 pts/0 R 20:59 6:37 widget-what-sit/cmake-build-mock/widget-what-sit.elf can0
I was also able to see the gadget file desciptors with:
declare -p gadget
declare -ar gadget=([0]="61" [1]="56)
So, the `gadget` coproc's `stdin` is hiding behind filedenoscriptor 56 and it's `stdout` is hiding behind file denoscriptor 61. I was able to confirm that by sending the `exit` command to the `gadget`'s `stdin` with:
echo exit >${gadget[1]}
and the `widget-gadget.elf` process noped out, as it should.
But then, I couldn't do the same thing with the `widget-what-sit.elf` process. Because some of my mock program names have punctuation in them that aren't conducive to shell symbol names. That's why I use the syntax `"${mock//[[:punct:]]/}"
$ declare -p whatsit
bash: declare: whatsit: not found
It's not there. And I'm eventually going to add the thing-ama-jig mock program to the bouquet as well, so I need to be able to access those file denoscriptors for all of my mock processes.
The warning:
bash: warning: executecoproc: coproc 4:gadget still exists
is apparently from when it launches the
What's going wrong? What am I missing?
https://redd.it/1j2ttcv
@r_bash
So, I have my docker container in which I want to run my native binaries. Let's say I have
declare -r PROJECT='widget'
declare -ra MOCKS=(gadget what-sit) # thing-ama-jig)
in a file called project.sh, and when another noscriptlet called session.sh where I source that in, and then I loop over MOCKS to launch all of the programs:
for mock in ${MOCK@}; do
echo "Executing coprocess '${PROJECT}-${mock}/cmake-build-mock/${PROJECT}-${mock}.elf ${@}' as ${mock//[:punct:]/}"
coproc "${mock//[[:punct:]]/}" { ${PROJECT}-${mock}/cmake-build-mock/${PROJECT}-${mock}.elf "${@}"; }
# Plug co-process "${mock//[:punct:]/}" into the command-line interface.
done
And for the first mock program, `gadget`, it's working great. All of my mock programs are sitting out there, pretty as you please, I just need to get them all executing as named coprocs and then I can work on stitching together all of the file denoscriptors into something that makes sense.
$ . session.sh can0
Executing coprocess 'widget-gadget/cmake-build-mock/widget-gadget.elf can0' as gadget
Executing coprocess 'widget-what-sit/cmake-build-mock/widget-what-sit.elf can0' as whatsit
bash: warning: executecoproc: coproc [4:gadget] still exists
session.sh: line 14: widget-gadget/cmake-build-mock/widget-gadget.elf: cannot execute: required file not found
Well, it was working for the first mock program. Now, it's not. I was able to confirm the coprocesses were running with:
$ ps aux
...
root 6 99.5 0.0 3376 1720 pts/0 R 20:59 6:37 widget-gadget/cmake-build-mock/widget-gadget.elf can0
root 8 99.5 0.0 3376 1720 pts/0 R 20:59 6:37 widget-what-sit/cmake-build-mock/widget-what-sit.elf can0
I was also able to see the gadget file desciptors with:
declare -p gadget
declare -ar gadget=([0]="61" [1]="56)
So, the `gadget` coproc's `stdin` is hiding behind filedenoscriptor 56 and it's `stdout` is hiding behind file denoscriptor 61. I was able to confirm that by sending the `exit` command to the `gadget`'s `stdin` with:
echo exit >${gadget[1]}
and the `widget-gadget.elf` process noped out, as it should.
But then, I couldn't do the same thing with the `widget-what-sit.elf` process. Because some of my mock program names have punctuation in them that aren't conducive to shell symbol names. That's why I use the syntax `"${mock//[[:punct:]]/}"
, so all of the punctuation marks will become underscores, which are valid symbol name characters. That makes the widget-what-sit.elf's coprocess name into whatsit`. But if I try to list what-sit's file denoscriptors:$ declare -p whatsit
bash: declare: whatsit: not found
It's not there. And I'm eventually going to add the thing-ama-jig mock program to the bouquet as well, so I need to be able to access those file denoscriptors for all of my mock processes.
The warning:
bash: warning: executecoproc: coproc 4:gadget still exists
is apparently from when it launches the
widget-what-sit.elf coprocess and the gadget coprocess still exists at that moment, and so I guess it's not creating the what_sit file denoscriptor array. But, it's supposed to!What's going wrong? What am I missing?
https://redd.it/1j2ttcv
@r_bash
Is there a limitation of sorts when using bash and SFTP?
This is what i have so far, and im a total novice here.
Bash
#!/bin/bash
# Configuration
REMOTE_HOST="your-ec2-hostname-or-ip"
REMOTE_USER="ec2-user" # Change to your EC2 username (e.g., ec2-user, ubuntu)
REMOTE_DIR="/app/test123"
LOCAL_DIR=“/app/test/app/backend/xeg"
KEY_PATH="$HOME/.ssh/id_rsa" # Path to your SSH private key
EMAIL_TO="your-email@example.com,colleague@example.com" # Comma-separated list of email recipients
# Use a directly created email content variable
EMAIL_CONTENT=""
# Function to log messages to both console and email variable
log_message() {
local message="$1"
local timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
echo "${timestamp} - ${message}"
EMAIL_CONTENT="${EMAIL_CONTENT}${timestamp} - ${message}
"
}
# Start logging
log_message "Starting SFTP sync process"
log_message "Attempting to connect to $REMOTE_HOST as $REMOTE_USER"
# Create local directory if it doesn't exist
if ! mkdir -p "$LOCAL_DIR" 2>/dev/null; then
log_message "ERROR: Cannot create local directory at $LOCAL_DIR"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - Directory Creation Failed" "${EMAIL_TO}"
exit 1
fi
log_message "Local directory confirmed at $LOCAL_DIR"
# Check if SSH key exists
if [ ! -f "$KEY_PATH" ]; then
log_message "ERROR: SSH key not found at $KEY_PATH"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - SSH Key Not Found" "${EMAIL_TO}"
exit 1
fi
log_message "SSH key found at $KEY_PATH"
# Create a temporary SFTP batch file
BATCH_FILE=$(mktemp 2>/dev/null)
if [ $? -ne 0 ]; then
# If mktemp fails, create batch file in current directory
BATCH_FILE="./sftp_batch_$(date +%s).txt"
touch "$BATCH_FILE" 2>/dev/null
if [ $? -ne 0 ]; then
log_message "ERROR: Cannot create temporary batch file"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - Temp File Creation Failed" "${EMAIL_TO}"
exit 1
fi
fi
cat > "$BATCH_FILE" << EOF
cd $REMOTE_DIR
lcd $LOCAL_DIR
ls -la
mget *
bye
EOF
log_message "Created SFTP batch file at $BATCH_FILE"
# Execute the SFTP command with the batch file
log_message "Executing SFTP commands"
SFTP_OUTPUT=$(sftp -i "$KEY_PATH" -b "$BATCH_FILE" "${REMOTE_USER}@${REMOTE_HOST}" 2>&1)
SFTP_STATUS=$?
# Add SFTP output to email content
log_message "--- SFTP Output ---"
EMAIL_CONTENT="${EMAIL_CONTENT}${SFTP_OUTPUT}
"
log_message "-------------------"
# Check if SFTP was successful
if [ $SFTP_STATUS -eq 0 ]; then
log_message "SFTP connection and file transfer successful"
# Check if remote directory exists by looking for errors in the output
if echo "$SFTP_OUTPUT" | grep -q "No such file or directory\|not found"; then
log_message "WARNING: Remote directory may not exist or is empty"
fi
# Count and list files transferred
if [ -d "$LOCAL_DIR" ]; then
# Capture list of files before and after transfer with detailed logging
log_message "DEBUG: Taking snapshot of files before transfer"
BEFORE_FILES=$(find "$LOCAL_DIR" -type f -name "*" 2>/dev/null | sort)
BEFORE_COUNT=$(echo "$BEFORE_FILES" | wc -l)
log_message "DEBUG: Files before transfer: $BEFORE_COUNT"
# Add some files to the debug log
if [ $BEFORE_COUNT -gt 0 ]; then
SAMPLE_BEFORE=$(echo "$BEFORE_FILES" | head -n 5)
log_message "DEBUG: Sample files before:
$SAMPLE_BEFORE"
fi
# Extract information about transferred files from SFTP output
log_message "DEBUG: Raw SFTP output:"
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Raw SFTP Output:
$SFTP_OUTPUT
"
TRANSFERRED_FILES=$(echo "$SFTP_OUTPUT" | grep -E "^Fetching" | awk '{print $2}')
log_message "DEBUG: Files reported as transferred by SFTP: $(echo "$TRANSFERRED_FILES" | wc -w)"
# Sleep briefly to ensure file operations are complete
sleep 2
# Capture list of files after transfer
log_message "DEBUG: Taking snapshot of
This is what i have so far, and im a total novice here.
Bash
#!/bin/bash
# Configuration
REMOTE_HOST="your-ec2-hostname-or-ip"
REMOTE_USER="ec2-user" # Change to your EC2 username (e.g., ec2-user, ubuntu)
REMOTE_DIR="/app/test123"
LOCAL_DIR=“/app/test/app/backend/xeg"
KEY_PATH="$HOME/.ssh/id_rsa" # Path to your SSH private key
EMAIL_TO="your-email@example.com,colleague@example.com" # Comma-separated list of email recipients
# Use a directly created email content variable
EMAIL_CONTENT=""
# Function to log messages to both console and email variable
log_message() {
local message="$1"
local timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
echo "${timestamp} - ${message}"
EMAIL_CONTENT="${EMAIL_CONTENT}${timestamp} - ${message}
"
}
# Start logging
log_message "Starting SFTP sync process"
log_message "Attempting to connect to $REMOTE_HOST as $REMOTE_USER"
# Create local directory if it doesn't exist
if ! mkdir -p "$LOCAL_DIR" 2>/dev/null; then
log_message "ERROR: Cannot create local directory at $LOCAL_DIR"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - Directory Creation Failed" "${EMAIL_TO}"
exit 1
fi
log_message "Local directory confirmed at $LOCAL_DIR"
# Check if SSH key exists
if [ ! -f "$KEY_PATH" ]; then
log_message "ERROR: SSH key not found at $KEY_PATH"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - SSH Key Not Found" "${EMAIL_TO}"
exit 1
fi
log_message "SSH key found at $KEY_PATH"
# Create a temporary SFTP batch file
BATCH_FILE=$(mktemp 2>/dev/null)
if [ $? -ne 0 ]; then
# If mktemp fails, create batch file in current directory
BATCH_FILE="./sftp_batch_$(date +%s).txt"
touch "$BATCH_FILE" 2>/dev/null
if [ $? -ne 0 ]; then
log_message "ERROR: Cannot create temporary batch file"
echo "$EMAIL_CONTENT" | mail -s "[ERROR] SFTP Transfer - Temp File Creation Failed" "${EMAIL_TO}"
exit 1
fi
fi
cat > "$BATCH_FILE" << EOF
cd $REMOTE_DIR
lcd $LOCAL_DIR
ls -la
mget *
bye
EOF
log_message "Created SFTP batch file at $BATCH_FILE"
# Execute the SFTP command with the batch file
log_message "Executing SFTP commands"
SFTP_OUTPUT=$(sftp -i "$KEY_PATH" -b "$BATCH_FILE" "${REMOTE_USER}@${REMOTE_HOST}" 2>&1)
SFTP_STATUS=$?
# Add SFTP output to email content
log_message "--- SFTP Output ---"
EMAIL_CONTENT="${EMAIL_CONTENT}${SFTP_OUTPUT}
"
log_message "-------------------"
# Check if SFTP was successful
if [ $SFTP_STATUS -eq 0 ]; then
log_message "SFTP connection and file transfer successful"
# Check if remote directory exists by looking for errors in the output
if echo "$SFTP_OUTPUT" | grep -q "No such file or directory\|not found"; then
log_message "WARNING: Remote directory may not exist or is empty"
fi
# Count and list files transferred
if [ -d "$LOCAL_DIR" ]; then
# Capture list of files before and after transfer with detailed logging
log_message "DEBUG: Taking snapshot of files before transfer"
BEFORE_FILES=$(find "$LOCAL_DIR" -type f -name "*" 2>/dev/null | sort)
BEFORE_COUNT=$(echo "$BEFORE_FILES" | wc -l)
log_message "DEBUG: Files before transfer: $BEFORE_COUNT"
# Add some files to the debug log
if [ $BEFORE_COUNT -gt 0 ]; then
SAMPLE_BEFORE=$(echo "$BEFORE_FILES" | head -n 5)
log_message "DEBUG: Sample files before:
$SAMPLE_BEFORE"
fi
# Extract information about transferred files from SFTP output
log_message "DEBUG: Raw SFTP output:"
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Raw SFTP Output:
$SFTP_OUTPUT
"
TRANSFERRED_FILES=$(echo "$SFTP_OUTPUT" | grep -E "^Fetching" | awk '{print $2}')
log_message "DEBUG: Files reported as transferred by SFTP: $(echo "$TRANSFERRED_FILES" | wc -w)"
# Sleep briefly to ensure file operations are complete
sleep 2
# Capture list of files after transfer
log_message "DEBUG: Taking snapshot of
files after transfer"
AFTER_FILES=$(find "$LOCAL_DIR" -type f -name "*" 2>/dev/null | sort)
AFTER_COUNT=$(echo "$AFTER_FILES" | wc -l)
log_message "DEBUG: Files after transfer: $AFTER_COUNT"
# Determine if new files were transferred by comparing counts
if [ $AFTER_COUNT -gt $BEFORE_COUNT ]; then
NEW_FILES_COUNT=$((AFTER_COUNT - BEFORE_COUNT))
log_message "Transferred $NEW_FILES_COUNT new files to $LOCAL_DIR"
# Identify which files are new by comparing before and after
NEW_FILES=$(comm -13 <(echo "$BEFORE_FILES") <(echo "$AFTER_FILES"))
log_message "DEBUG: Newly detected files:"
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Newly detected files:
$NEW_FILES
"
# List the transferred files if any
if [ -n "$TRANSFERRED_FILES" ]; then
log_message "Files transferred:"
EMAIL_CONTENT="${EMAIL_CONTENT}--- Files Transferred ---
$TRANSFERRED_FILES
"
fi
# Success subject with timestamp
EMAIL_SUBJECT="[SFTP-SYNC] Transfer Complete - $(date '+%Y-%m-%d %H:%M') - $NEW_FILES_COUNT Files"
else
log_message "No new files detected, nothing transferred"
# Info subject with timestamp
EMAIL_SUBJECT="[SFTP-SYNC] Completed - $(date '+%Y-%m-%d %H:%M') - No Changes"
# Additional debugging if no files detected
log_message "DEBUG: Checking if files exist on remote server"
REMOTE_LS=$(echo "$SFTP_OUTPUT" | grep -A 100 "sftp>" | grep -v "sftp>")
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Remote directory listing:
$REMOTE_LS
"
fi
# Get list of all files in destination
log_message "Total files in destination directory: $AFTER_COUNT"
FILE_LIST=$(ls -la "$LOCAL_DIR" 2>/dev/null || echo "Cannot list directory contents")
EMAIL_CONTENT="${EMAIL_CONTENT}--- Directory Contents ---
${FILE_LIST}
"
else
log_message "WARNING: Local directory no longer exists after transfer"
fi
# Email subject for success
EMAIL_SUBJECT="[SUCCESS] SFTP File Transfer Complete"
else
log_message "ERROR: SFTP connection or file transfer failed with status $SFTP_STATUS"
# Email subject for failure
EMAIL_SUBJECT="[FAILED] SFTP File Transfer Error"
fi
# Clean up the temporary batch file
rm -f "$BATCH_FILE" 2>/dev/null
log_message "SFTP sync process completed"
# Create a temporary file for the email content
EMAIL_FILE=$(mktemp)
if [ $? -eq 0 ]; then
# Write email content to file
echo "$EMAIL_CONTENT" > "$EMAIL_FILE"
# Send email with content-type explicitly set to text/plain
(
echo "To: ${EMAIL_TO}"
echo "Subject: ${EMAIL_SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/plain; charset=utf-8"
echo "Content-Transfer-Encoding: 8bit"
echo ""
cat "$EMAIL_FILE"
) | /usr/sbin/sendmail -t
# Remove temporary email file
rm -f "$EMAIL_FILE"
else
# Fallback to regular mail if temp file creation fails
echo "$EMAIL_CONTENT" | mail -s "${EMAIL_SUBJECT}" "${EMAIL_TO}"
fi
# Output completion message to console
echo "SFTP sync completed. Notification sent to ${EMAIL_TO}"
Apologies for the formatting ahead of time. I dont usually post, if someone could tell me what shortcut to use to format it properly would be appreciated.
Code is garbage, I’m sure, but i am not an expert by any means - Essentally what i am trying to accomplish, is to pull down files from a remote server via sftp. Running this noscript, it does it, but for some reason , when i try to add logic for the notifications, via email to update up when there are no changes, email subject should read - no changes - but whenever i add a file, it shows it and still runs a. The batch job process and pulls the file, but it keeps spitting out “changes” no matter if there is a change..e.x a file added…I can’t
AFTER_FILES=$(find "$LOCAL_DIR" -type f -name "*" 2>/dev/null | sort)
AFTER_COUNT=$(echo "$AFTER_FILES" | wc -l)
log_message "DEBUG: Files after transfer: $AFTER_COUNT"
# Determine if new files were transferred by comparing counts
if [ $AFTER_COUNT -gt $BEFORE_COUNT ]; then
NEW_FILES_COUNT=$((AFTER_COUNT - BEFORE_COUNT))
log_message "Transferred $NEW_FILES_COUNT new files to $LOCAL_DIR"
# Identify which files are new by comparing before and after
NEW_FILES=$(comm -13 <(echo "$BEFORE_FILES") <(echo "$AFTER_FILES"))
log_message "DEBUG: Newly detected files:"
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Newly detected files:
$NEW_FILES
"
# List the transferred files if any
if [ -n "$TRANSFERRED_FILES" ]; then
log_message "Files transferred:"
EMAIL_CONTENT="${EMAIL_CONTENT}--- Files Transferred ---
$TRANSFERRED_FILES
"
fi
# Success subject with timestamp
EMAIL_SUBJECT="[SFTP-SYNC] Transfer Complete - $(date '+%Y-%m-%d %H:%M') - $NEW_FILES_COUNT Files"
else
log_message "No new files detected, nothing transferred"
# Info subject with timestamp
EMAIL_SUBJECT="[SFTP-SYNC] Completed - $(date '+%Y-%m-%d %H:%M') - No Changes"
# Additional debugging if no files detected
log_message "DEBUG: Checking if files exist on remote server"
REMOTE_LS=$(echo "$SFTP_OUTPUT" | grep -A 100 "sftp>" | grep -v "sftp>")
EMAIL_CONTENT="${EMAIL_CONTENT}DEBUG: Remote directory listing:
$REMOTE_LS
"
fi
# Get list of all files in destination
log_message "Total files in destination directory: $AFTER_COUNT"
FILE_LIST=$(ls -la "$LOCAL_DIR" 2>/dev/null || echo "Cannot list directory contents")
EMAIL_CONTENT="${EMAIL_CONTENT}--- Directory Contents ---
${FILE_LIST}
"
else
log_message "WARNING: Local directory no longer exists after transfer"
fi
# Email subject for success
EMAIL_SUBJECT="[SUCCESS] SFTP File Transfer Complete"
else
log_message "ERROR: SFTP connection or file transfer failed with status $SFTP_STATUS"
# Email subject for failure
EMAIL_SUBJECT="[FAILED] SFTP File Transfer Error"
fi
# Clean up the temporary batch file
rm -f "$BATCH_FILE" 2>/dev/null
log_message "SFTP sync process completed"
# Create a temporary file for the email content
EMAIL_FILE=$(mktemp)
if [ $? -eq 0 ]; then
# Write email content to file
echo "$EMAIL_CONTENT" > "$EMAIL_FILE"
# Send email with content-type explicitly set to text/plain
(
echo "To: ${EMAIL_TO}"
echo "Subject: ${EMAIL_SUBJECT}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/plain; charset=utf-8"
echo "Content-Transfer-Encoding: 8bit"
echo ""
cat "$EMAIL_FILE"
) | /usr/sbin/sendmail -t
# Remove temporary email file
rm -f "$EMAIL_FILE"
else
# Fallback to regular mail if temp file creation fails
echo "$EMAIL_CONTENT" | mail -s "${EMAIL_SUBJECT}" "${EMAIL_TO}"
fi
# Output completion message to console
echo "SFTP sync completed. Notification sent to ${EMAIL_TO}"
Apologies for the formatting ahead of time. I dont usually post, if someone could tell me what shortcut to use to format it properly would be appreciated.
Code is garbage, I’m sure, but i am not an expert by any means - Essentally what i am trying to accomplish, is to pull down files from a remote server via sftp. Running this noscript, it does it, but for some reason , when i try to add logic for the notifications, via email to update up when there are no changes, email subject should read - no changes - but whenever i add a file, it shows it and still runs a. The batch job process and pulls the file, but it keeps spitting out “changes” no matter if there is a change..e.x a file added…I can’t
tell if its my shitty code or something which is an underlying issue - open to feedback :)
https://redd.it/1j3ncpj
@r_bash
https://redd.it/1j3ncpj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A process I'm trying to pipe data into using a named pipe reports a "Read error"
Hello everyone!! So I've been trying for the last hour and a half to get the "fftest" process to receive the input "0", so it would run its part of the program. It used to work, but after a couple of attempts and deleting the named pipe file it just stopped working.
The problematic code is this:
#!/bin/bash
loop(){
while [ 1 ]
do
sleep 2
echo 0 > pipef
sleep 18
done
}
mkfifo pipef
cat > pipef &
mypid=$!
trap "pkill -f fftest" SIGINT
loop &
looppid=$!
fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick < pipef
kill $mypid
kill $looppid
rm pipef
I'm creating the loop function that's responsible for the data input, then I open the pipe, then I run the loop, so it would pipe its data when the time comes and then I run the "fftest" command itself. The moment that command is ran it exits, reporting a "Read error".
This code used to work before, until it randomly stopped (that's why I created the new one in an attempt to fix it):
#!/bin/bash
mkfifo pipef
cat > pipef &
mypid=$!
fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick < pipef &
sleep 2
while [ 1 ]
do
echo 0 > pipef
sleep 20
done
kill $mypid
rm pipef
If you have found my mistake, please tell me!! Thank you so so much in advance!!! <3
Edit: This is the output with
+ mkfifo pipef
+ mypid=31874
+ trap 'pkill -f fftest' SIGINT
+ cat
+ looppid=31875
+ fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick
+ loop
+ [ -n 1 ]
+ sleep 2
Force feedback test program.
HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES
Device /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick opened
Features:
Absolute axes: X, Y, Z, RX, RY, RZ, Hat 0 X, Hat 0 Y,
[3F 00 03 00 00 00 00 00 ]
Relative axes:
00 00
Force feedback effects types: Periodic, Rumble, Gain,
Force feedback periodic effects: Square, Triangle, Sine,
[00 00 00 00 00 00 00 00 00 00 03 07 01 00 00 00 ]
Number of simultaneous effects: 16
Setting master gain to 75% ... OK
Uploading effect #0 (Periodic sinusoidal) ... OK (id 0)
Uploading effect #1 (Constant) ... Error: Invalid argument
Uploading effect #2 (Spring) ... Error: Invalid argument
Uploading effect #3 (Damper) ... Error: Invalid argument
Uploading effect #4 (Strong rumble, with heavy motor) ... OK (id 1)
Uploading effect #5 (Weak rumble, with light motor) ... OK (id 2)
Enter effect number, -1 to exit
Read error
Stopping effects
+ kill 31874
./start.sh: line 24: kill: (31874) - No such process
+ kill 31875
+ rm pipef
https://redd.it/1j45ksb
@r_bash
Hello everyone!! So I've been trying for the last hour and a half to get the "fftest" process to receive the input "0", so it would run its part of the program. It used to work, but after a couple of attempts and deleting the named pipe file it just stopped working.
The problematic code is this:
#!/bin/bash
loop(){
while [ 1 ]
do
sleep 2
echo 0 > pipef
sleep 18
done
}
mkfifo pipef
cat > pipef &
mypid=$!
trap "pkill -f fftest" SIGINT
loop &
looppid=$!
fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick < pipef
kill $mypid
kill $looppid
rm pipef
I'm creating the loop function that's responsible for the data input, then I open the pipe, then I run the loop, so it would pipe its data when the time comes and then I run the "fftest" command itself. The moment that command is ran it exits, reporting a "Read error".
This code used to work before, until it randomly stopped (that's why I created the new one in an attempt to fix it):
#!/bin/bash
mkfifo pipef
cat > pipef &
mypid=$!
fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick < pipef &
sleep 2
while [ 1 ]
do
echo 0 > pipef
sleep 20
done
kill $mypid
rm pipef
If you have found my mistake, please tell me!! Thank you so so much in advance!!! <3
Edit: This is the output with
set -x:+ mkfifo pipef
+ mypid=31874
+ trap 'pkill -f fftest' SIGINT
+ cat
+ looppid=31875
+ fftest /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick
+ loop
+ [ -n 1 ]
+ sleep 2
Force feedback test program.
HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES
Device /dev/input/by-id/usb-MediaTekInc.XBOXACC000000000-event-joystick opened
Features:
Absolute axes: X, Y, Z, RX, RY, RZ, Hat 0 X, Hat 0 Y,
[3F 00 03 00 00 00 00 00 ]
Relative axes:
00 00
Force feedback effects types: Periodic, Rumble, Gain,
Force feedback periodic effects: Square, Triangle, Sine,
[00 00 00 00 00 00 00 00 00 00 03 07 01 00 00 00 ]
Number of simultaneous effects: 16
Setting master gain to 75% ... OK
Uploading effect #0 (Periodic sinusoidal) ... OK (id 0)
Uploading effect #1 (Constant) ... Error: Invalid argument
Uploading effect #2 (Spring) ... Error: Invalid argument
Uploading effect #3 (Damper) ... Error: Invalid argument
Uploading effect #4 (Strong rumble, with heavy motor) ... OK (id 1)
Uploading effect #5 (Weak rumble, with light motor) ... OK (id 2)
Enter effect number, -1 to exit
Read error
Stopping effects
+ kill 31874
./start.sh: line 24: kill: (31874) - No such process
+ kill 31875
+ rm pipef
https://redd.it/1j45ksb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Problem with imgur upload noscript
The noscript that xfce screenshot tool is using to upload screenshots to imgur stopped working, but i don't know if the problem is with the sctipt of changes in imgur api. I am just average linux user. Can someone check the noscript: https://pastebin.com/5SunZpkk
https://redd.it/1j4t512
@r_bash
The noscript that xfce screenshot tool is using to upload screenshots to imgur stopped working, but i don't know if the problem is with the sctipt of changes in imgur api. I am just average linux user. Can someone check the noscript: https://pastebin.com/5SunZpkk
https://redd.it/1j4t512
@r_bash
Pastebin
#!/bin/sh# Permission to use, copy, modify, and/or distribute this software - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I've created windows switcher
I created something handy today and I would like to share it and maybe get your opinion/suggestion. I've created window switcher noscripts that mapped to Ubuntu custom shortcut keys. When triggered it instantly finds the intended windows and switch to it no matter where you are in the workspace (reduces the need for constant alt+tab). This minimizes time and effort to navigate if you have many windows and workspace on. It uses wmctrl tool
I've created so far four switchers: terminal switcher, firefox switcher, google-chatgpt switcher, youtube switcher since these are my primary window cycles
[ubuntu keyboard custom shortcuts setting](https://preview.redd.it/3xkjyctq11ne1.png?width=515&format=png&auto=webp&s=d15a68225b5afefa4bc84b64ed40bfd2b3f40e61)
//terminal\_sw.sh (switch to your terminal. I keep all terminals in one workspace)
#!/bin/bash
wmctrl -a ubuntu <your_username>@ubuntu:~
//google\_sw.sh (it actually is a chatgpt switcher on google browser. The only way i know how to do chatgpt switcher)
#!/bin/bash
wmctrl -a Google Chrome
//firefox\_sw.sh (targeted firefox browser, need to explicitly exclude "YouTube" window to avoid conflating with youtube-only window)
#!/bin/bash
# Find a Firefox window that does not contain "YouTube"
window_id=$(wmctrl -lx | grep "Mozilla Firefox" | grep -v "YouTube" | awk '{print $1}' | head -n 1)
if [ -n "$window_id" ]; then
wmctrl -ia "$window_id"
else
echo "No matching Firefox window found."
fi
//youtube\_sw.sh (targeted firefox with youtube-only window)
#!/bin/bash
# Find a Firefox window that contains "YouTube"
window_id=$(wmctrl -lx | grep "YouTube — Mozilla Firefox" | awk '{print $1}' | head -n 1)
if [ -n "$window_id" ]; then
wmctrl -ia "$window_id"
else
echo "No YouTube window found."
fi
https://redd.it/1j4qy4v
@r_bash
I created something handy today and I would like to share it and maybe get your opinion/suggestion. I've created window switcher noscripts that mapped to Ubuntu custom shortcut keys. When triggered it instantly finds the intended windows and switch to it no matter where you are in the workspace (reduces the need for constant alt+tab). This minimizes time and effort to navigate if you have many windows and workspace on. It uses wmctrl tool
I've created so far four switchers: terminal switcher, firefox switcher, google-chatgpt switcher, youtube switcher since these are my primary window cycles
[ubuntu keyboard custom shortcuts setting](https://preview.redd.it/3xkjyctq11ne1.png?width=515&format=png&auto=webp&s=d15a68225b5afefa4bc84b64ed40bfd2b3f40e61)
//terminal\_sw.sh (switch to your terminal. I keep all terminals in one workspace)
#!/bin/bash
wmctrl -a ubuntu <your_username>@ubuntu:~
//google\_sw.sh (it actually is a chatgpt switcher on google browser. The only way i know how to do chatgpt switcher)
#!/bin/bash
wmctrl -a Google Chrome
//firefox\_sw.sh (targeted firefox browser, need to explicitly exclude "YouTube" window to avoid conflating with youtube-only window)
#!/bin/bash
# Find a Firefox window that does not contain "YouTube"
window_id=$(wmctrl -lx | grep "Mozilla Firefox" | grep -v "YouTube" | awk '{print $1}' | head -n 1)
if [ -n "$window_id" ]; then
wmctrl -ia "$window_id"
else
echo "No matching Firefox window found."
fi
//youtube\_sw.sh (targeted firefox with youtube-only window)
#!/bin/bash
# Find a Firefox window that contains "YouTube"
window_id=$(wmctrl -lx | grep "YouTube — Mozilla Firefox" | awk '{print $1}' | head -n 1)
if [ -n "$window_id" ]; then
wmctrl -ia "$window_id"
else
echo "No YouTube window found."
fi
https://redd.it/1j4qy4v
@r_bash
New to bash, had a question about weird command substitution case
I've been taking an introduction to Linux and Bash course at my college and we came across this case when using echo and command substitution with variables. I thought that it would actually print the random number, but no matter how many echo $() I put, it always prints $RANDOM
export META='$RANDOM'
echo $(echo $(echo $META))
Can someone help me understand this interaction? Thank you
https://redd.it/1j4fz6t
@r_bash
I've been taking an introduction to Linux and Bash course at my college and we came across this case when using echo and command substitution with variables. I thought that it would actually print the random number, but no matter how many echo $() I put, it always prints $RANDOM
export META='$RANDOM'
echo $(echo $(echo $META))
Can someone help me understand this interaction? Thank you
https://redd.it/1j4fz6t
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
how to make my bash noscript take lesser ram?
So, I wrote a bash noscript that would randomize my wallpaper from a folder and i made it such that it starts up when my pc boots up in hyprland.conf file but there is one drawback and that is gradually it takes up all the ram.
HOW do i make it such that it doesn't take all the ram?
https://redd.it/1j5fe56
@r_bash
So, I wrote a bash noscript that would randomize my wallpaper from a folder and i made it such that it starts up when my pc boots up in hyprland.conf file but there is one drawback and that is gradually it takes up all the ram.
HOW do i make it such that it doesn't take all the ram?
https://redd.it/1j5fe56
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Tar2Deb
Pure bash noscript that converts a tar file into a deb file
in order to install tar2deb you need wget, note only works for debian based distros.
features
automatically move images in the extracted tar directory that holds a subdirectory with the most images then export it as a variable then moves to the deb directory, the deb directory is needed in order to create a .deb file, it uses imagemagick to move each image by dimension, before the dimensions and after is extracts the tar file it will ask the user what does want the package name be, does not allow numbers except 2, then the name of the package the user chooses will be exported as a variable, then it will ask the user what is version of your package, once the user chosen its version for the package it will be exported as a variable then combine those to variables like this $PackageName-$Version then it will create the directory with those 2 variables then it will ask the user what name of the maintainer, whatever name the user decides will be exported as a variable, then it asks the user what is the package about, whatever the users type will also because exported as variable, then it will create the control file in the deb dir DEBIAN folder, then once the control file is created, it will create the directories in the deb directory, then it will find a graphical executable file (excluding binary files) and move to deb_dir/usr/bin after it does then it will go the dimensions after it moves the dimension it will ask the user a yes or no prompt asking if it wants to rename all image files moved into one name if the users say no then it will ask the user if it wants to rename a file from the numerical list and whatever numbers it chooses it will prompt the user what the name to be for the file then it combine that name with the file extension and renames the chosen file with the name that user choose, then it create a desktop if there is not an desktop file in the tar directory it will ask the user if it wants to create a desktop since there is not located in tar directory if the users say user then it do a prompt asking the user what executable file it wants to choose for desktop file then it will show a numerical list showing a list of images and whatever image the user chooses will be the icon of the desktop file once the desktop file is
how to install tar2deb
sudo apt install wget && wget https://github.com/GitXpresso/Tar2Deb/releases/download/v.1.0.0/tar2deb-1.0.0.deb && sudo apt install -y ./tar2deb-1.0.0.deb
https://redd.it/1j5u1xh
@r_bash
Pure bash noscript that converts a tar file into a deb file
in order to install tar2deb you need wget, note only works for debian based distros.
features
automatically move images in the extracted tar directory that holds a subdirectory with the most images then export it as a variable then moves to the deb directory, the deb directory is needed in order to create a .deb file, it uses imagemagick to move each image by dimension, before the dimensions and after is extracts the tar file it will ask the user what does want the package name be, does not allow numbers except 2, then the name of the package the user chooses will be exported as a variable, then it will ask the user what is version of your package, once the user chosen its version for the package it will be exported as a variable then combine those to variables like this $PackageName-$Version then it will create the directory with those 2 variables then it will ask the user what name of the maintainer, whatever name the user decides will be exported as a variable, then it asks the user what is the package about, whatever the users type will also because exported as variable, then it will create the control file in the deb dir DEBIAN folder, then once the control file is created, it will create the directories in the deb directory, then it will find a graphical executable file (excluding binary files) and move to deb_dir/usr/bin after it does then it will go the dimensions after it moves the dimension it will ask the user a yes or no prompt asking if it wants to rename all image files moved into one name if the users say no then it will ask the user if it wants to rename a file from the numerical list and whatever numbers it chooses it will prompt the user what the name to be for the file then it combine that name with the file extension and renames the chosen file with the name that user choose, then it create a desktop if there is not an desktop file in the tar directory it will ask the user if it wants to create a desktop since there is not located in tar directory if the users say user then it do a prompt asking the user what executable file it wants to choose for desktop file then it will show a numerical list showing a list of images and whatever image the user chooses will be the icon of the desktop file once the desktop file is
how to install tar2deb
sudo apt install wget && wget https://github.com/GitXpresso/Tar2Deb/releases/download/v.1.0.0/tar2deb-1.0.0.deb && sudo apt install -y ./tar2deb-1.0.0.deb
https://redd.it/1j5u1xh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
backup copy of .bashrc for the root directory?
i found a copy of .bashrc in /etc/skel but the .bashrc file in /root is another one
https://redd.it/1j6v9l7
@r_bash
i found a copy of .bashrc in /etc/skel but the .bashrc file in /root is another one
https://redd.it/1j6v9l7
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community