I accidentally created a bunch of ~ signs - how do I delete them?
https://redd.it/1g36w4k
@r_bash
Script for creating local web env
Hi, I'm practicing creating a bash script to streamline setting up a local web development environment for WordPress. Anyone care to give some feedback on this script or some best practices in general?#!/bin/bash# Define colorsGREEN='\033[0;32m'YELLOW='\033[0;33m'RED='\033[0;31m'RESET='\033[0m'# Ask user for project nameread -p "Enter the project name: " PROJECT_NAME# Check if input is not empty and doesn't containt spacesif [[ -z "$PROJECT_NAME" || "$PROJECT_NAME" =~ [[:space:]] ]]; thenecho -e "${YELLOW}Project name cannot be empty or contain spaces.${RESET}"exit 1fi# Define variablesPROJECT_DIR="/var/www/html/$PROJECT_NAME"DB_NAME="$PROJECT_NAME"DB_USER="root"DB_PASSWORD=""DB_HOST="localhost"WP_HOME="http://$PROJECT_NAME.local"WP_SITEURL="http://$PROJECT_NAME.local/wp"APACHE_CONF="/etc/apache2/sites-available/$PROJECT_NAME.conf"ETC_HOSTS="/etc/hosts"# Check if the project directory already existsif [ -d "$PROJECT_DIR" ]; thenecho -e "${YELLOW}$PROJECT_NAME already exists. Please choose another name.${RESET}"exit 1fi# Create the directory using bedrockcomposer create-project roots/bedrock "$PROJECT_DIR"# Ensure Apache can read and write to the Bedrock directorysudo chown -R www-data:www-data "$PROJECT_DIR"sudo find "$PROJECT_DIR" -type d -exec chmod 755 {} \;sudo find "$PROJECT_DIR" -type f -exec chmod 755 {} \;# Create the databaseecho "Creating database $DB_NAME..."mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS $DB_NAME;"# Create a new Apache configuration for the projectecho "Creating Apache configuration for Bedrock"sudo bash -c "cat > $APACHE_CONF <<EOL<VirtualHost *:80>ServerName "$PROJECT_NAME".localDocumentRoot "$PROJECT_DIR"/web<Directory "$PROJECT_DIR"/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted</Directory>ErrorLog /var/log/apache2/"$PROJECT_NAME"-error.logCustomLog /var/log/apache2/"$PROJECT_NAME"-access.log combined</VirtualHost>EOL"# Give www-data permissions to write to /var/log/apache2/ directorysudo usermod -a -G adm www-data# Enable the new site and required modulesecho "Enablind the new site and required Apache modules..."sudo a2ensite "$PROJECT_NAME".confsudo a2enmod rewrite# Add the project to /etc/hosts if it doesn't existecho "Adding $PROJECT_NAME.local to /etc/hosts..."if ! grep -q "$PROJECT_NAME.local" /etc/hosts; thensudo bash -c "echo '127.0.0.1 $PROJECT_NAME.local' >> /etc/hosts"fi# Reload Apache for changes to take effectsystemctl reload apache2echo -e "${GREEN}$PROJECT_NAME setup completed! You can access it at http://$PROJECT_NAME.local${RESET}"
https://redd.it/1g2qdqk
@r_bash
probably stupid mistake
i dont know why but this dont work
printf "%d" $((RANDOM & 1)){$string}; echo
when this does
printf "%d" $((RANDOM & 1)){,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}; echo
https://redd.it/1g2j8n0
@r_bash
I would like to make this less stupid but have no idea of what to use to get the same result.
echo $((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))$((RANDOM % 2))
the result is a random sequence of number of 0s and 1s
1010010101111111010010110110001011100100100010110110101001101010111001001111110010100101011100101000000011010100111000101101110001111010
https://redd.it/1g1y4i6
@r_bash
What boredom does to a man replicating the old TVs 'no signal' color bars in BASH
https://redd.it/1g16wrq
@r_bash
"sudo <command>" doesn't use system wide bash config.
I have created a system wide configuration for bash at /etc/bash.bashrc to format the prompt and source pywal colors so that I don't need to manage a separate config file for root and my user account. However, the colors are only applied when I run a command without elevated privileges. So, it works fine for my user account, and if I actually sign in as root before issuing the command; but if I were to type "sudo ls" while being signed in as my user, the text output remains completely white instead of using my color palette. Can anyone in here explain this behavior and would you be willing to tell me what I need to do to get it working correctly? Here are the contents of my /etc/bash.bashrc:
/etc
$ cat bash.bashrc
# If not running interactively, don't do anything
[ $- != *i* ] && return
# Grab colors from pywal
(cat /home/ego/.cache/wal/sequences &)
source /home/ego/.cache/wal/colors-tty.sh
# Prompt
PS1='\n\w\n\$ '
# Enable color output
alias ls="ls --color=auto"
https://redd.it/1g0ujfr
@r_bash
My ASCII graphics basic demo engine in BASH language: ISObash.
https://redd.it/1g0jaqj
@r_bash
A Bash Script To Display Animated Christmas Tree In Terminal
https://redd.it/1g0f2jc
@r_bash
Avoid passing arguments to function until all items have been looped through ?
Hi,
I have the below part of a script which gets information from a system which the user inputs.
function rrupreparation ()
{
kubeworker=$1
charu=2024
timez=3
if -z $(ssh -q $kubeworker ssh -q $rruaddr cat /etc/benetel-rootfs-version)
currver=$(ssh -q $kubeworker ssh -q $rruaddr cat /etc/benetel-rootfs-version)
then
if [ $currver == $upgradever ]
then
echo "$rruaddr UPGRADED"
else
echo "$rruaddr NOT UPGRADED"
fi
fi
}
function rruchecks ()
{
kubeworker=$1
rruaddr=$2
if -z $(ssh -q $kubeworker ssh -q $rruaddr cat /etc/benetel-rootfs-version)
currver=$(ssh -q $kubeworker ssh -q $rruaddr cat /etc/benetel-rootfs-version)
then
if [ $currver == $upgradever ]
then
stat="(U)"
tval=TXMeanPower
else
stat="(NU)"
tval=tssi
fi
fi
echo "$stat | $currver | $kubeworker | $rruaddr
rrupreparation $kubeworker
}
function findnodes ()
{
findnodes1=1
for kubeworkers in $allkubes;
do
kubeworker=$( echo $kubeworkers | cut -c 6- )
echo $kubeworker
done
read -p "Find RRU in Worker : " kubeworker
for rruaddr in $(ssh -q $kubeworker arp -n | grep 10.42.8 | grep ether | awk '{print $1}')
do
rruchecks $kubeworker $rruaddr
done
}
findnodes
Script output once run
bai-ran-cluster-worker0
bai-ran-cluster-worker1
bai-ran-cluster-worker2
bai-ran-cluster-worker3
bai-ran-cluster-worker4
bai-ran-cluster-worker5
bai-ran-cluster-worker6
Find RRU in Worker : bai-ran-cluster-worker3 <--- User inputs any name from the above list
So in this case the user input is passed as arguments from findnodes function to rruchecks function which then checks the system, and gives the below result.
(NU) | RAN650-3V0.8.2patch2 |
NOT UPGRADED
(NU) | RAN650-3V0.8.2patch2 |
NOT UPGRADED
(NU) | RAN650-3V0.8.2patch2 |
NOT UPGRADED10.42.8.3510.42.8.3510.42.8.3610.42.8.3610.42.8.3710.42.8.37
In the above result the 1st line is the expected, the 2nd line is a result of the argument received in rruchecks being passed on to rrupreparation function.
How can I not pass the user input from rruchecks to rrupreparation until all systems have been checked in rruchecks ?
https://redd.it/1fzu7as
@r_bash
How are if, case, etc implemented internally?
I was thinking about it and I realized I had no idea- how do if, for, while, case, etc, all control the execution of separate commands on other lines? For example
if [ "$thing" == "blah" ]; then
echo "How does it know to not run this command if thing is not blah??"
fi
Is this something only builtin commands have the power to do? Or could if, case, etc, theoretically be implemented as external programs?
https://redd.it/1fxnch3
@r_bash
Shell scripting projects for 1 yoe helpdesk to get promoted to a new role?
What could that be?(in new company-switch)
https://redd.it/1fx6m6a
@r_bash
Rate my bash script
https://drive.google.com/file/d/1q7DVciDMbCrO4YyV6U4S4StgZ2ll5MFu/view
https://redd.it/1fx3pbb
@r_bash
what does "echo $$" do?
so question, what does "echo $$" do?
some people are saying that it prints the PID of the current instance of the shell you are on
other people are saying that it prints the PID of "a" or "the" script that's currently executing?
which is it? or is it both?
thank you
https://redd.it/1fwp9lf
@r_bash
ffmpeg bash question - How to create bash to cut out intro and outro from multiple videos
I'm trying to cut the intro and outro out of multiple videos with different beginning times and different end times using ffmpeg
The code I know of that will do this from a single video is
"ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mkv -c copy output.mkv"
But I don’t know how to tell ffmpeg to do this for multiple videos and to do this with different beginning times and different ending times so that it will do one right after the other
I am new to all of this so if anyone could help me, that would be amazing, thank you
https://redd.it/1fwjvy8
@r_bash
weird behavior from a bash line
hi there,
I wonder why :
find /home/jess/* -type f -iname "*" | wofi --show=dmenu | xargs -0 -I vim "{}"
returns
xargs: {}: No such file or directory
why the find arg isn't passed to vim ?
thx for help guys and girls
https://redd.it/1fuq7r2
@r_bash
Missing Alias??
hey, need help ☹️
so about a year ago, i remember setting up an alias that would take "docker" and replace it with "DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build" because i was getting annoyed and it saved me a ton of time.
the problem now, is that im starting to use docker again, and i cant find that alias declared anywhere. its not in .bashrc, .zshrc, .bash_profile, .profile,
i cant find it using grep (too many files, not enough CPU)
i need help. honestly its not a huge deal just spelling it wrong and then correcting it, but i need to find out where this thing is. is there any sort of log that will show everything executed on my machine? ive already tried recording with script shell_activity too. no results.
https://redd.it/1g2yth1
@r_bash
A bash banner
https://preview.redd.it/y17eh6ai7eud1.png?width=1142&format=png&auto=webp&s=7a7a7f394fb9996aade20227d11263ea3792e99a
Script here, minus the allergens/uv data since that requires a lot of extra infrastructure:
https://gist.github.com/robbieh/c12d355ea074a7aeef9d847d76ad69f8
This script is designed to be run in .bashrc so I get relevant info when I first sit down and open a terminal. After the first time it shows, new terminals will get a much more terse version so that it doesn't become annoying. That resets after an hour.
The script contains a way to make a header with figlet and run just about anything to the right of it. That was tricky to work out.
https://redd.it/1g2a7ja
@r_bash
Script to rename multiple files quickly using vim
https://redd.it/1g1hrtf
@r_bash
Super simple question - How can I keep Neovim from opening if fzf is closed with <C-c>?
I have a simple alias which uses fzf to search for and open a file in neovim:alias nv='nvim$(find . -maxdepth 1 -not -type d | fzf --preveiw="cat {}" --tmux)'
This works pretty much exactly as I want it to (although if it could be better I'd love to know how), but if I close the fzf using ctrl+c neovim will still open a new file.
https://redd.it/1g0zbv9
@r_bash
How to remove all directories that don't contain specific filetypes?
I've made a bit of mess of my music library and am sorting things with beets.io.
It's leaving behind a lot of cruft.
Is there a command I can run recuresibly that will delete all directories and files do not contain *.flac, *.mp3, *.ogg?
I've got hundreds of folders and subfolders much of which is just extra album art or *.m3u kinda stuff I would love to avoid manually going through them.
https://redd.it/1g0jq93
@r_bash
Stupid question but ...
Hello everyone,
I'm trying to set up a cron job to shut down my students' computers at a fixed time, but it doesn't work: the computers stay on.
I have 3 users on each computer:
Teacher
Student
root
In the "crontab -e" students I enter the following command:
14 17 * * 1-5 /sbin/shutdown -h +1
Thank you in advance for telling me where the error is.
Mark
https://redd.it/1g0gcm9
@r_bash
noob here progress bar
I have this simple function in .bashrc:0x0() { [ -z "$1" -o -r "$1" ] && curl --progress-bar -F"file=@${1:--}" -Fexpires=48 `https://0x0.st` || echo -e "error: bla bla bla"; }
it works perfectly but no progress bar is shown, why??
https://redd.it/1fzxxl4
@r_bash
BASH Tool that helps you solving THM and HTB machines & ctfs
# Hey pentesters & bash guys ,
I wanna share a tool I've been working on that I hope will help you all with THM rooms and HTB machines. It's called Sh0zack and 100 % in BASH
contains customized versions of popular tools like nmap, wfuzz, and linpeas directly within it , Designed specifically for CTFs and practice environments like THM and HTB.
GitHub Repository: https://github.com/sh0z3n/Sh0zack
I'd love for you all to try it out and let me know what you think. Ideas for additional tools or features you'd like to see integrated , Your feedback will be invaluable in making it even better.
usage
https://redd.it/1fzo42b
@r_bash
How do I finish a pipe early?
Hi.
I have this script that is supposed to get me the keyframes between two timestamps (in seconds). I want to use them in order to splice a video without having to reencode it at all. I also want to use ffmpeg for this.
My issue is that I have a big file and I want to finish the processing early under a certain condition. How do I do it from inside of an awk script? I've already used this exit in the early finish condition, but I think it only finishes the awk script early. I also don't know if it runs, because I don't know whether it's possible to print out some debug info when using awk. Edit: I've added print "blah"; at the beginning of the middle clause and I don't see it being printed, so I'm probably not matching anything or something? print inside of BEGIN does get printed. :/
I think it's also important to mention that this script was written with some chatgpt help, because I can't write awk things at all.
Thank you for your time.
https://pastebin.com/cGEK9EHH
#!/bin/bash
set -x #echo on
SOURCEVIDEO="$1"
STARTTIME="$2"
ENDTIME="$3"
# Get total number of frames for progress tracking
TOTALFRAMES=$(ffprobe -v error -selectstreams v:0 -countpackets -showentries stream=nbreadpackets -of csv=p=0 "$SOURCEVIDEO")
if -z "$TOTAL_FRAMES" ; then
echo "Error: Unable to retrieve the total number of frames."
exit 1
fi
# Initialize variables for tracking progress
framesprocessed=0
startframe=""
endframe=""
startdiff=999999
enddiff=999999
# Process frames
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g' |
awk -v start="$STARTTIME" -v end="$ENDTIME" '
BEGIN {
FS=" ";
print "start";
startframe="";
endframe="";
startdiff=999999;
enddiff=999999;
betweenframes="";
print "startend";
}
{
print "processing";
current = $2;
if (current > end) {
exit;
}
if (startframe == "" && current >= start) {
startframe = $1;
startdiff = current - start;
} else if (current >= start && (current - start) < startdiff) {
startframe = $1;
startdiff = current - start;
}
if (current <= end && (end - current) < enddiff) {
endframe = $1;
enddiff = end - current;
}
if (current >= start && current <= end) {
betweenframes = betweenframes $1 ",";
}
}
END {
print "\nProcessing completed."
print "Closest keyframe to start time: " startframe;
print "Closest keyframe to end time: " endframe;
print "All keyframes between start and end:";
print substr(betweenframes, 1, length(betweenframes)-1);
}'
Edit: I have debugged it a little more and I had a typo but I think I have a problem with sed.
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g'
The above doesn't output anything, but before sed the output is:
38:frame 9009
39:frame 10010
40:frame 11011
41:frame 12012
42:frame 13013
43:frame 14014
44:frame 15015
45:frame 16016
46:frame 17017
47:frame 18018
48:frame 19019
49:frame 20020
50:frame 21021
51:frame 22022
52:frame 23023
53:frame 24024
54:frame 25025
55:frame 26026
I'm not sure if sed is supposed to printout anything or not though. Probably it is supposed to do so?
https://redd.it/1fxhx2n
@r_bash
Getting the “logname” of a PID
Say I log into a box with account “abc”. I su to account “def” and run a script, helloworld.sh, as account “def”. If I run a ps -ef | grep helloworld, I will see the script running with account “def” as the owner. Is there a way I can map that back to the OG account “abc” to store that value into a variable?
Context: I have a script where I allow accounts to impersonate others. The impersonation is logged in the script’s log via the logname command, but I also have a “current users” report where I can see who’s currently running the script. I’d like the current users report to show that, while John is running the script, it’s actually Joe who’s impersonating John via an su.
I’ve tried ps -U and ps -u, but obviously, that didn’t work.
https://redd.it/1fx6n52
@r_bash
How do I replace part of a line with the output of a variable?
Hi all,
I am writing a script that will update my IPv4 on my Wireguard server as my dynamic IP changes. Here is what I have so far:
#! /bin/bash
CurrentIP= curl -S -s -o /dev/null http://ipinfo.io/ip
WireguardIP= grep -q "pivpnHOST=" /etc/pivpn/wireguard/setupVars.conf |tr -d 'pivpnHOST='
if "$Current_IP" = "$Wireguard_IP" ;then
exit
else
#replace WireguardIP with CurrentIP in setupVars.conf
fi
exit 0
when trying to find my answer I searched through stack overflow and think I need to use awk -v, however; I don't know how to in this case. Any pointers would be appreciated.
https://redd.it/1fwxq9l
@r_bash
How do i change the colors of that bar?
https://preview.redd.it/w3hvszskswsd1.png?width=1032&format=png&auto=webp&s=5b31a400d02ea56e41adeb17da96327373068443
Hello, so i am using Chris Titus Tech's custom bash config but the colors dont fit with the pallete of my terminal (im making my system Dune themed).
Here is the .bashrc file: https://github.com/ChrisTitusTech/mybash/blob/main/.bashrc , i really tried to find where i can change those colors but couldnt find the line.
My ocd is killing me ;(
https://redd.it/1fwmwol
@r_bash
what does the $ BY ITSELF mean in bash?
i understand it has something to do with variables but i googled it and it couldn't get a straight answer on what the $ alone means, so i wanted to ask here
thank you
https://redd.it/1fv4k1r
@r_bash
Help creating script to email on boot
I am looking for help in creating a script to email me when a system boots or reboots. I have tried various online sources but nothing seems to work. I would like to have my Raspberry Pi running Raspbian email me when it boots. I have frequent power outages and want to be able to have the always on Pi let me know when it boots so that I know the power had gone out and I can check the logs for the duration.
Can anyone help me with this?
https://redd.it/1fupucl
@r_bash