Is it possible to convert bash noscripts into Python noscripts?
Just wondering If it's possible
https://redd.it/1cpljyt
@r_bash
Just wondering If it's possible
https://redd.it/1cpljyt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why is last command not running?
I have a noscript that creates a temp file with filenames, it then feeds that list to clamscan for scanning only files that have been modified. I'd like to open the log file with the application "kate" at the end of the noscript and then exit the existing terminal. It isn't working. The noscript runs the scan, but then just exits without opening the logfile. What am I doing wrong?
#!/usr/bin/bash
# CLAMSCAN RECENTLY CHANGED FILES
# DIRECTORIES TO SCAN
scandir="/home/"
# TEMPORARY FILE
listfile=$(mktemp -t clamscan.XXXXXX) || exit 1
# LOCATION OF LOG FILE
logfile="/home/clamweekly.log"
# MAKE LIST OF NEW FILES
if [ -f "$logfile" ]
then
# use newer files then logfile
find "$scandir" -type f -cnewer "$logfile" -fprint "$listfile"
else
# scan modified in last 7 days
find "$scandir" -type f -ctime -7 -fprint "$listfile"
fi
if [ -s "$listfile" ]
then
# Scan files
clamscan -i -f "$listfile" > "$logfile"
else
# remove the empty file, contains no info
rm -f "$listfile"
fi
# OPEN THE LOG FILE TO REVIEW AND CLOSE THE TERMINAL
kate $logfile & disown
exit
https://redd.it/1cq428r
@r_bash
I have a noscript that creates a temp file with filenames, it then feeds that list to clamscan for scanning only files that have been modified. I'd like to open the log file with the application "kate" at the end of the noscript and then exit the existing terminal. It isn't working. The noscript runs the scan, but then just exits without opening the logfile. What am I doing wrong?
#!/usr/bin/bash
# CLAMSCAN RECENTLY CHANGED FILES
# DIRECTORIES TO SCAN
scandir="/home/"
# TEMPORARY FILE
listfile=$(mktemp -t clamscan.XXXXXX) || exit 1
# LOCATION OF LOG FILE
logfile="/home/clamweekly.log"
# MAKE LIST OF NEW FILES
if [ -f "$logfile" ]
then
# use newer files then logfile
find "$scandir" -type f -cnewer "$logfile" -fprint "$listfile"
else
# scan modified in last 7 days
find "$scandir" -type f -ctime -7 -fprint "$listfile"
fi
if [ -s "$listfile" ]
then
# Scan files
clamscan -i -f "$listfile" > "$logfile"
else
# remove the empty file, contains no info
rm -f "$listfile"
fi
# OPEN THE LOG FILE TO REVIEW AND CLOSE THE TERMINAL
kate $logfile & disown
exit
https://redd.it/1cq428r
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Data onion help
I am making a kind of data onion of sorts for someone where the end goal is to find a text file.
I do not know a lot about bash or coding in general but the person who im making it for does. He's basically a pro. I would like to get some help with encrypting or hiding the file using bash, and just generally making it difficult/ annoying.
Any help is appreciated.
https://redd.it/1cqb7lf
@r_bash
I am making a kind of data onion of sorts for someone where the end goal is to find a text file.
I do not know a lot about bash or coding in general but the person who im making it for does. He's basically a pro. I would like to get some help with encrypting or hiding the file using bash, and just generally making it difficult/ annoying.
Any help is appreciated.
https://redd.it/1cqb7lf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Run command as another user exactly as if the other user opened a prompt and typed the command
Im the
Output
Tried
Output
Is there a way so all the things I define in the
https://redd.it/1cqvdo7
@r_bash
Im the
root and want to run a command as the notroot user, how to make the command run like this -su - notroot
echo $PATH
whoami
echo $-
Output
/usr/local/bin:<paths from .bashrc>
notroot
himBHs
Tried
/bin/bash -c 'sudo --login -u notroot echo $-'
/bin/bash -c 'sudo --login -u notroot echo $PATH'
Output
hBc
Missing .bashrc paths
Is there a way so all the things I define in the
.bashrc (mainly additions to PATH) will show when exec command as another user https://redd.it/1cqvdo7
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Script for Watch Folder and then Copy sub-folders
New to noscripting, so I apologize for the most-likely-obvious question.
I'm looking to create a watch folder (testsource) and copy the sub-folders and their contents to a different location (testdest), then delete the original.
#!/bin/bash
source_d="/test/testsource/"
destination_d1="/test/testdest/"
inotifywait -m -q -e close_write "$source_d" |
while read -r path action file; do
cp -- "$path$file" "$destination_d1"
# rm -- "$path$file"
done
When I create files in /test/testsource, they are detected and copied to /test/testdest. But if I copy a folder with a testfile in it (/test/testsource/testfolder/testfile1) it does not. I did notice that if I then place a file into /test/testsource (test/testsource/testfile2), it will copy both the file as well as the other subfolder.
I presume its the "$path$file" format that is wrong, but I don't know what should be used. I tried "$path" but it didn't copy anything. I tried with " cp -r $path" but also didn't get it to work.
https://redd.it/1cqyi1f
@r_bash
New to noscripting, so I apologize for the most-likely-obvious question.
I'm looking to create a watch folder (testsource) and copy the sub-folders and their contents to a different location (testdest), then delete the original.
#!/bin/bash
source_d="/test/testsource/"
destination_d1="/test/testdest/"
inotifywait -m -q -e close_write "$source_d" |
while read -r path action file; do
cp -- "$path$file" "$destination_d1"
# rm -- "$path$file"
done
When I create files in /test/testsource, they are detected and copied to /test/testdest. But if I copy a folder with a testfile in it (/test/testsource/testfolder/testfile1) it does not. I did notice that if I then place a file into /test/testsource (test/testsource/testfile2), it will copy both the file as well as the other subfolder.
I presume its the "$path$file" format that is wrong, but I don't know what should be used. I tried "$path" but it didn't copy anything. I tried with " cp -r $path" but also didn't get it to work.
https://redd.it/1cqyi1f
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Get file contents into a variable - the file is referenced by a variable
I want to get the contents of a file into a variable, but the file is referenced by a variable.
The code below hangs the session, and I have to break out.
It is the same if I remove the quote marks.
If I simply
I have also tried using quotes on the $resultsfile (fails with
I feel I'm missing something basic but can't quite get the syntax correct.
https://redd.it/1crc9d3
@r_bash
I want to get the contents of a file into a variable, but the file is referenced by a variable.
The code below hangs the session, and I have to break out.
resultsfile=~/results.txtmessagebody="$(cat $resultsfile)"It is the same if I remove the quote marks.
If I simply
messagebody=$(cat ~/results.txt) it works as I expect.I have also tried using quotes on the $resultsfile (fails with
cat: '': No such file or directory, and placing $resultsfile inside escaped quotes (fails with cat: '""': No such file or directoryI feel I'm missing something basic but can't quite get the syntax correct.
https://redd.it/1crc9d3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can Make be used as a replacement for bash?
Hi,
I am a complete novice at
Now I don't understand make not I claim to be an expert in bash, but just by googling a bit i understood that make is mainly used as a built tool and might not be as general purpose as bash. Is that it or can make actually be used as a replacement of bash? I don't find the argument "easier to debug" convincing enough but see it as a more of a skill issue e.g. same goes for make for me, I don't know make so it's not easier to debug for me.
https://redd.it/1crhvpt
@r_bash
Hi,
I am a complete novice at
make butbhave used bash fairly regularly. Recently my manager suggested to use make instead of bash. Not just in some use cases but in general, like "lets do everything with make as it is easier to debug than bash". Now I don't understand make not I claim to be an expert in bash, but just by googling a bit i understood that make is mainly used as a built tool and might not be as general purpose as bash. Is that it or can make actually be used as a replacement of bash? I don't find the argument "easier to debug" convincing enough but see it as a more of a skill issue e.g. same goes for make for me, I don't know make so it's not easier to debug for me.
https://redd.it/1crhvpt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
what is a "stack" in the bash shell?
hello, i keep hearing people talk about this thing called a "stack" in the bash shell
what is that? that is a "stack"?
thank you
https://redd.it/1crkta6
@r_bash
hello, i keep hearing people talk about this thing called a "stack" in the bash shell
what is that? that is a "stack"?
thank you
https://redd.it/1crkta6
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help me improving my tmux start up noscript
So after I boot up my WSL2 Ubuntu I have a small noscript to setup my tmux session and start VsCode. It does (mostly) what it's suppost to do and I'm working on the next iteration:
#!/bin/bash
SESSIONNAME="main"
tmux has-session -t $SESSIONNAME >? /dev/null
if $? != 0
then
tmux new-session -s $SESSIONNAME -n admin -d
tmux new-window -n project -t $SESSIONNAME:
tmux send-keys -t $SESSIONNAME 'cd ./pyprojects/' Enter 'code' Enter
fi
tmux attach -t $SESSIONNAME
cd ~/pyprojects
So far so good. The frist flaw of this program is that it will create another 'project' window if called again. I'm unsure how to prevent this.
Secondly, the next step would be to source the last utilized Python venv. I haven't though of how to keep track of this. So for now I would go with just a default venv, stored in an env variable.
At the moment I'm mainly wondering if
Also I'm interested in your ideas on how to track what venv had been used last. I thought using the fact, that VsCode keeps track of the last project, however I havn't been able to find/use this information.
https://redd.it/1croxg6
@r_bash
So after I boot up my WSL2 Ubuntu I have a small noscript to setup my tmux session and start VsCode. It does (mostly) what it's suppost to do and I'm working on the next iteration:
#!/bin/bash
SESSIONNAME="main"
tmux has-session -t $SESSIONNAME >? /dev/null
if $? != 0
then
tmux new-session -s $SESSIONNAME -n admin -d
tmux new-window -n project -t $SESSIONNAME:
tmux send-keys -t $SESSIONNAME 'cd ./pyprojects/' Enter 'code' Enter
fi
tmux attach -t $SESSIONNAME
cd ~/pyprojects
So far so good. The frist flaw of this program is that it will create another 'project' window if called again. I'm unsure how to prevent this.
Secondly, the next step would be to source the last utilized Python venv. I haven't though of how to keep track of this. So for now I would go with just a default venv, stored in an env variable.
At the moment I'm mainly wondering if
send-keys is actually the best / proper way of interacting with my tmux session. I'm affraid I'll be limited in what I can do from this bash noscript, as "things are happening in another console". So I'd be interested in your adivice here.Also I'm interested in your ideas on how to track what venv had been used last. I thought using the fact, that VsCode keeps track of the last project, however I havn't been able to find/use this information.
https://redd.it/1croxg6
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
need help with xargs or mv
so im trying to move all files and folders within /sdcard1/Download/ to /sdcard/daya excluding a folder name dualnine in /sdcard1/Download. Here is the command i used
but i get an error saying mv: dir at '/sdcard/daya/'
Can anyone pls explain I don't understand what is wrong
https://redd.it/1crq4fw
@r_bash
so im trying to move all files and folders within /sdcard1/Download/ to /sdcard/daya excluding a folder name dualnine in /sdcard1/Download. Here is the command i used
find /sdcard1/Download/ -mindepth 1 -maxdepth 1 ! -name dualnine | xargs mv -f /sdcard/daya/but i get an error saying mv: dir at '/sdcard/daya/'
Can anyone pls explain I don't understand what is wrong
https://redd.it/1crq4fw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Script for ffmpeg help
Using this noscript . It compresses videos with different bitrates but it is not working as expected. Can anyone help?
https://redd.it/1cryxfy
@r_bash
Using this noscript . It compresses videos with different bitrates but it is not working as expected. Can anyone help?
https://redd.it/1cryxfy
@r_bash
No Code Developers Tools - CodersTool.com
Share Code Snippets
Code snippets can improve your workflows and save time coding. Use this online tool to share code snippets.
Bash and Unix course help
Hello!
I have been working for the past year or so as a DevOps engineer, the position relies on many tools and technologies and basic-intermediate Unix and python. I have been encountering more and more difficulties lately at work due to my limited knowledge of Unix, I know and understand the basics but I'm having some difficulties with Intermediate level stuff. So far, I have been heavily relying on ChatGPT to save me in these scenarios but this deducts from my learning.
I want a course on the Intermediate level that will help me with generic Unix and bash noscripting, stuff like getting a directory and splitting it based on "/" then printing one element, stuff like escaping characters and when they are used (bonus points if Dockerfiles are mentioned in specific), how quotation marks work and why " is different than ' or """ . I have already read on these things but I was wondering if a specific course would cover these better than lazily reading a bit of documentation and putting 0 practice in it.
https://redd.it/1csgfsx
@r_bash
Hello!
I have been working for the past year or so as a DevOps engineer, the position relies on many tools and technologies and basic-intermediate Unix and python. I have been encountering more and more difficulties lately at work due to my limited knowledge of Unix, I know and understand the basics but I'm having some difficulties with Intermediate level stuff. So far, I have been heavily relying on ChatGPT to save me in these scenarios but this deducts from my learning.
I want a course on the Intermediate level that will help me with generic Unix and bash noscripting, stuff like getting a directory and splitting it based on "/" then printing one element, stuff like escaping characters and when they are used (bonus points if Dockerfiles are mentioned in specific), how quotation marks work and why " is different than ' or """ . I have already read on these things but I was wondering if a specific course would cover these better than lazily reading a bit of documentation and putting 0 practice in it.
https://redd.it/1csgfsx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
.bashrc that overrides every command?
I wanted to know if it is possible to create like some troll .bashrc that every command/shell builtin commands/path to executable file it encounters it will override it and do some other action.
https://redd.it/1csi3s8
@r_bash
I wanted to know if it is possible to create like some troll .bashrc that every command/shell builtin commands/path to executable file it encounters it will override it and do some other action.
https://redd.it/1csi3s8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Amber - the programming language compiled to Bash
Hi! I'm Paweł, and I'm excited to introduce **Amber**, a new programming language that compiles to Bash. Amber offers three key advantages over traditional shell noscripting:
* **A modern and familiar syntax**, similar to Ruby or Rust, that's easy to learn and use.
* **Type safety**, which ensures robust error handling and prevents common mistakes.
* **Runtime safety**, which means the compiler forces you to handle all potential errors during compilation, making your code more reliable.
Want to learn more? Check out [https://amber-lang.com](https://amber-lang.com) for additional information.
https://preview.redd.it/2exig1gm3n0d1.png?width=1854&format=png&auto=webp&s=658c49e477dc2705444d001d752a95d35ace275d
https://redd.it/1cst3zy
@r_bash
Hi! I'm Paweł, and I'm excited to introduce **Amber**, a new programming language that compiles to Bash. Amber offers three key advantages over traditional shell noscripting:
* **A modern and familiar syntax**, similar to Ruby or Rust, that's easy to learn and use.
* **Type safety**, which ensures robust error handling and prevents common mistakes.
* **Runtime safety**, which means the compiler forces you to handle all potential errors during compilation, making your code more reliable.
Want to learn more? Check out [https://amber-lang.com](https://amber-lang.com) for additional information.
https://preview.redd.it/2exig1gm3n0d1.png?width=1854&format=png&auto=webp&s=658c49e477dc2705444d001d752a95d35ace275d
https://redd.it/1cst3zy
@r_bash
Welcome to Amber
Amber The Programming Language
using sed to insert '[foo]' string in a file
I am looking for a way to insert multiple lines of text into a file. I am exploring sed. I understand that the \[\] are meta characters that introduce a character class but is there a way to escape them so that I can insert them as plain text; something like this into a text file:
[header]
answer=1
foo=true
bar=never
This is the sed command I am using. I am trying to exca
# sed -i '76 i\\
\[fips_sect\] \\
activate = 1 \\
conditional-errors = 1\\
security-checks = 1 \\
' /usr/local/ssl/openssl.cnf
That attempt fails with an error:
sed: -e expression #1, char 32: unterminated address regex
What's my best approach here?
https://redd.it/1csvbeo
@r_bash
I am looking for a way to insert multiple lines of text into a file. I am exploring sed. I understand that the \[\] are meta characters that introduce a character class but is there a way to escape them so that I can insert them as plain text; something like this into a text file:
[header]
answer=1
foo=true
bar=never
This is the sed command I am using. I am trying to exca
# sed -i '76 i\\
\[fips_sect\] \\
activate = 1 \\
conditional-errors = 1\\
security-checks = 1 \\
' /usr/local/ssl/openssl.cnf
That attempt fails with an error:
sed: -e expression #1, char 32: unterminated address regex
What's my best approach here?
https://redd.it/1csvbeo
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Could someone help on below for automation ideas from linux perspective?
https://www.reddit.com/r/sre/comments/1ct0wu9/automation_ideas_from_ops_perspective/?utm_source=share&utm_medium=mweb3x&utm_name=post_embed&utm_term=1&utm_content=1
https://redd.it/1ct0zld
@r_bash
https://www.reddit.com/r/sre/comments/1ct0wu9/automation_ideas_from_ops_perspective/?utm_source=share&utm_medium=mweb3x&utm_name=post_embed&utm_term=1&utm_content=1
https://redd.it/1ct0zld
@r_bash
Reddit
From the sre community on Reddit
Explore this post and more from the sre community
find , ALTERNATIVE? while looping recursively
.
These work like a charm and seems to be the de-facto standard when user needs to execute operations recursively while looping through files.
But... I'm asking if, over the years, some alternatives were developed in order to "unificate", instead of involving calling
Something like this, for example:
To me, I found some sort of "unification" in GNU Parallel by setting nr. of jobs to
https://redd.it/1ct7ocf
@r_bash
$ while IFS= read -r -d '' V; do SOMETHING "$V"; done < <(find . -type f -print0)
.
$ find . -type f -exec bash -c 'SOMETHING "$1"' _ {} \;
These work like a charm and seems to be the de-facto standard when user needs to execute operations recursively while looping through files.
But... I'm asking if, over the years, some alternatives were developed in order to "unificate", instead of involving calling
while, read, print0 flag of find and Process Substitution.Something like this, for example:
floop /path SOMETHING
To me, I found some sort of "unification" in GNU Parallel by setting nr. of jobs to
1https://redd.it/1ct7ocf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
cron and $(date +"%Y%m%d-%H%M%S")
Hi,
I am trying to get this to work in crontab to produce directories named date +"%Y%m%d-%H%M%S" e.g dump-20240515-123413
This command works perfectly well on the command line in bash.
/usr/bin/mongodump -o /data/mongodbdump/dump-"$(date +"%Y%m%d-%H%M%S")"
but cron misinteprets the date as :
May 16 10:38:01 srv1 CROND[355784]: (root) CMDEND ([ -d /data/mongodbdump ] && /usr/bin/mongodump -o /data/mongodbdump/dump-"$(date +")
Also, I tried without the extra set of "
/usr/bin/mongodump -o /data/mongodbdump/dump-$(date +"%Y%m%d-%H%M%S")
How can I get this to work properly and create a file name with a format of dump-20240516-103412
Any help appreciated.
EK
https://redd.it/1ct8dpg
@r_bash
Hi,
I am trying to get this to work in crontab to produce directories named date +"%Y%m%d-%H%M%S" e.g dump-20240515-123413
This command works perfectly well on the command line in bash.
/usr/bin/mongodump -o /data/mongodbdump/dump-"$(date +"%Y%m%d-%H%M%S")"
but cron misinteprets the date as :
May 16 10:38:01 srv1 CROND[355784]: (root) CMDEND ([ -d /data/mongodbdump ] && /usr/bin/mongodump -o /data/mongodbdump/dump-"$(date +")
Also, I tried without the extra set of "
/usr/bin/mongodump -o /data/mongodbdump/dump-$(date +"%Y%m%d-%H%M%S")
How can I get this to work properly and create a file name with a format of dump-20240516-103412
Any help appreciated.
EK
https://redd.it/1ct8dpg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
what is "option+d" in the context of bash keyboard shortcuts?
hello, i'm trying to learn all the bash keyboard shortcuts and i came across this
https://kapeli.com/cheat\_sheets/Bash\_Shortcuts.docset/Contents/Resources/Documents/index
and one of the keyboard shortcuts is "option+d"
what does this mean? what key is the "option" key?
thank you
https://redd.it/1ctc0mx
@r_bash
hello, i'm trying to learn all the bash keyboard shortcuts and i came across this
https://kapeli.com/cheat\_sheets/Bash\_Shortcuts.docset/Contents/Resources/Documents/index
and one of the keyboard shortcuts is "option+d"
what does this mean? what key is the "option" key?
thank you
https://redd.it/1ctc0mx
@r_bash
what is the "ctrl+xx" keyboard shortcut?
hello, i'm trying to learn bashes keyboard shortcuts and one of the keyboard shortcuts i found was "ctrl+xx" and it says
"Move between start of command line and current cursor position (and back again)"
i tried this one out on my terminal and it's just highlighting and moving the cursor around randomly, does anyone have any experience with this shortcut and can tell me how it works?
thank you
https://redd.it/1cu3dvz
@r_bash
hello, i'm trying to learn bashes keyboard shortcuts and one of the keyboard shortcuts i found was "ctrl+xx" and it says
"Move between start of command line and current cursor position (and back again)"
i tried this one out on my terminal and it's just highlighting and moving the cursor around randomly, does anyone have any experience with this shortcut and can tell me how it works?
thank you
https://redd.it/1cu3dvz
@r_bash