sed not working within for loop
I'm trying to do this loop
for ALLSERVER in "$HOME/Games/Servers/Minecraft/"
do
echo $( sed '53!d' "$ALLSERVER/server-properties" )
done
but `sed` is interpreting the wildcard character incorrectly, in a way that `echo` doesn't, producing the following error:
sed: can't read /home/user/Games/Servers/Minecraft//server-properties: No such file or directory
How can I make it properly substitute the wildcard for the directory in the current iteration?
https://redd.it/1f63mbt
@r_bash
I'm trying to do this loop
for ALLSERVER in "$HOME/Games/Servers/Minecraft/"
do
echo $( sed '53!d' "$ALLSERVER/server-properties" )
done
but `sed` is interpreting the wildcard character incorrectly, in a way that `echo` doesn't, producing the following error:
sed: can't read /home/user/Games/Servers/Minecraft//server-properties: No such file or directory
How can I make it properly substitute the wildcard for the directory in the current iteration?
https://redd.it/1f63mbt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
[Seeking advice + critique] I wrote a collection of noscripts on creating and using LUKS volume on Linux natively rather than with third party software like veracrypt
Scripts Link: https://gitlab.com/cy_narrator/lukshelper
Complementary article: https://utsavpoudyal.com.np/posts/Create-Encrypted-File-Container-in-Linux/
So I wanted a way to deal with sensitive files on Linux without necessarily having to encrypt the entire disk of a flash drive. Basically, what I want is a way to create an encrypted file container on Linux, sort of what Veracrypt allows you to do but without any third party software, this ensures that the volume is available even when that third party software is unavailable.
The most concern I have is in my luksCreate.sh noscript. That noscript takes in a password from the user and feeds into cryptsetup. This is done for convinience, otherwise, the user has to enter the same password three times, first two times for when cryptsetup luksFormat was performed on the volume, last one when the noscript opens the volume to format it with a filesystem. I also had to do some calculations to calculate appropriate `count` for the given block size and volume size.
Someone mentioned that it is possible for someone to terminate the noscript early and read the $password1 and $password2, I tried and it is not the case because they are bash variables, not environment variables. But regardless, the passwords are overwritten with empty string after use.
Some defaults were assumed when creating the volume which is explained in my article in **Notes and Disclaimer** section.
I dont think the password handling concern is present in other noscripts as other noscripts just call on cryptsetup and make cryptsetup prompt for the password itself. But regardless, please let me know if anything else also can be improved.
I am still learning bash, I have hardly written bash before, those too were written couple of years ago and I have totally forgotten how they were written.
Please also let me know ideas on how to make these noscripts better.
https://redd.it/1f6ie7b
@r_bash
Scripts Link: https://gitlab.com/cy_narrator/lukshelper
Complementary article: https://utsavpoudyal.com.np/posts/Create-Encrypted-File-Container-in-Linux/
So I wanted a way to deal with sensitive files on Linux without necessarily having to encrypt the entire disk of a flash drive. Basically, what I want is a way to create an encrypted file container on Linux, sort of what Veracrypt allows you to do but without any third party software, this ensures that the volume is available even when that third party software is unavailable.
The most concern I have is in my luksCreate.sh noscript. That noscript takes in a password from the user and feeds into cryptsetup. This is done for convinience, otherwise, the user has to enter the same password three times, first two times for when cryptsetup luksFormat was performed on the volume, last one when the noscript opens the volume to format it with a filesystem. I also had to do some calculations to calculate appropriate `count` for the given block size and volume size.
Someone mentioned that it is possible for someone to terminate the noscript early and read the $password1 and $password2, I tried and it is not the case because they are bash variables, not environment variables. But regardless, the passwords are overwritten with empty string after use.
Some defaults were assumed when creating the volume which is explained in my article in **Notes and Disclaimer** section.
I dont think the password handling concern is present in other noscripts as other noscripts just call on cryptsetup and make cryptsetup prompt for the password itself. But regardless, please let me know if anything else also can be improved.
I am still learning bash, I have hardly written bash before, those too were written couple of years ago and I have totally forgotten how they were written.
Please also let me know ideas on how to make these noscripts better.
https://redd.it/1f6ie7b
@r_bash
GitLab
Utsav Poudyal / luksHelper · GitLab
Escaping characters is grep
I am trying to grep some text between two values but I can't escape the characters.
viewME('jkhkjhkjhkjhudydsdvvytvd')
I use this command but it keeps giving me a ( error. I tested the regex in a tester and it works without issue yet when I try grep I get errors on Arch linux. What am I missing?
grep -E '(?<=viewME\\(\\').*(?=\\'\\))'
https://redd.it/1f6ulzc
@r_bash
I am trying to grep some text between two values but I can't escape the characters.
viewME('jkhkjhkjhkjhudydsdvvytvd')
I use this command but it keeps giving me a ( error. I tested the regex in a tester and it works without issue yet when I try grep I get errors on Arch linux. What am I missing?
grep -E '(?<=viewME\\(\\').*(?=\\'\\))'
https://redd.it/1f6ulzc
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Script doesn't terminate after simple background process exits
Script:
#!/usr/bin/env bash
# Control Tasmota plug via MQTT
status() {
mosquittosub -h addr -u user -P 1 -t 'stat/plugc/RESULT' -C 1 | jq -r .Timers &
}
status
mosquittopub -h addr -u user -P 1 -t cmnd/plugc/timers -m "OFF"
I run
If I run those commands on the interactive shell directly, it behaves as expected--I get back my command line cursor.
Any ideas?
https://redd.it/1f6zypv
@r_bash
Script:
#!/usr/bin/env bash
# Control Tasmota plug via MQTT
status() {
mosquittosub -h addr -u user -P 1 -t 'stat/plugc/RESULT' -C 1 | jq -r .Timers &
}
status
mosquittopub -h addr -u user -P 1 -t cmnd/plugc/timers -m "OFF"
I run
mosquitto_sub in the background so it can listen and return the result of mosquitto_pub, after which it exits. I get that result, but the noscript appears to "hang" (shell prompt doesn't give me back the cursor) even though the mosquitto_sub process ends (it no longer has a pid). I need to press Enter on the shell and it returns with success code 0.If I run those commands on the interactive shell directly, it behaves as expected--I get back my command line cursor.
Any ideas?
https://redd.it/1f6zypv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is It Possible to Make SSHD Generate a New sshd_config File?
Hi all
I have made some changes to my `/etc/ssh/sshd_config` file,
and I would like to compare them to the original untouched file.
Is it possible to ask SSHD to somehow generate a new sshd_config file?
Like what I had before changing any settings..
Thank you
https://redd.it/1f79iiz
@r_bash
Hi all
I have made some changes to my `/etc/ssh/sshd_config` file,
and I would like to compare them to the original untouched file.
Is it possible to ask SSHD to somehow generate a new sshd_config file?
Like what I had before changing any settings..
Thank you
https://redd.it/1f79iiz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is It Possible to Ask "man" to Show Only a Specific Setting?
Hi all
If you run
you see that man has several options to filter the output,
for example:
> man man options [section page ...] ...
Now assume this:
You want to run
and thens see only the paragraph for the
Is it possible to point the command to a specific setting/paragraph?
Thank you
https://redd.it/1f7ay1b
@r_bash
Hi all
If you run
man man, you see that man has several options to filter the output,
for example:
> man man options [section page ...] ...
Now assume this:
You want to run
man sshd_config, and thens see only the paragraph for the
PubkeyAcceptedKeyTypes setting.Is it possible to point the command to a specific setting/paragraph?
Thank you
https://redd.it/1f7ay1b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Which PubkeyAcceptedAlgorithm Should I Choose for SSHD, Now that "ssh-rsa" is Less Recommended?
Hi all
Since SSHD removed "ssh-rsa" from the Default List for
I conclude that it's an old algorithm and SSHD is trying to push users to something newer and more secure.
So in
we can see the following list of Algorithms that are now in the default list:
ssh-ed25519-cert-v01@openssh.com,
ecdsa-sha2-nistp256-cert-v01@openssh.com,
ecdsa-sha2-nistp384-cert-v01@openssh.com,
ecdsa-sha2-nistp521-cert-v01@openssh.com,
sk-ssh-ed25519-cert-v01@openssh.com,
sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,
rsa-sha2-512-cert-v01@openssh.com,
rsa-sha2-256-cert-v01@openssh.com,
ssh-ed25519,
ecdsa-sha2-nistp256,
ecdsa-sha2-nistp384,
ecdsa-sha2-nistp521,
sk-ssh-ed25519@openssh.com,
sk-ecdsa-sha2-nistp256@openssh.com,
rsa-sha2-512,
rsa-sha2-256
Which one should I choose?
And why some of them resemble the format of an Email Address?
Thank you
https://redd.it/1f7gb20
@r_bash
Hi all
Since SSHD removed "ssh-rsa" from the Default List for
PubkeyAcceptedAlgorithms, I conclude that it's an old algorithm and SSHD is trying to push users to something newer and more secure.
So in
man sshd_config, we can see the following list of Algorithms that are now in the default list:
ssh-ed25519-cert-v01@openssh.com,
ecdsa-sha2-nistp256-cert-v01@openssh.com,
ecdsa-sha2-nistp384-cert-v01@openssh.com,
ecdsa-sha2-nistp521-cert-v01@openssh.com,
sk-ssh-ed25519-cert-v01@openssh.com,
sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,
rsa-sha2-512-cert-v01@openssh.com,
rsa-sha2-256-cert-v01@openssh.com,
ssh-ed25519,
ecdsa-sha2-nistp256,
ecdsa-sha2-nistp384,
ecdsa-sha2-nistp521,
sk-ssh-ed25519@openssh.com,
sk-ecdsa-sha2-nistp256@openssh.com,
rsa-sha2-512,
rsa-sha2-256
Which one should I choose?
And why some of them resemble the format of an Email Address?
Thank you
https://redd.it/1f7gb20
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
[Critique] Aria2 moving downloads noscript
I’ve developed a noscript that moves completed downloads from Aria2. I’m seeking feedback on potential improvements. You can review the noscript here: [GitHub](https://github.com/macg4dave/aria_move).
I’m considering replacing the mv command with rsync and refining the variable management. Are there any other enhancements or best practices I should consider?
#!/bin/sh
# Variables for paths (no trailing slashes)
DOWNLOAD="/mnt/World/incoming"
COMPLETE="/mnt/World/completed"
LOG_FILE="/mnt/World/mvcompleted.log"
TASK_ID=$1
NUM_FILES=$2
SOURCE_FILE=$3
LOG_LEVEL=1 # 1=NORMAL, 2=NORMAL+INFO, 3=NORMAL+INFO+ERROR, 4=NORMAL+DEBUG+INFO+ERROR
# Function to log messages based on log level
log() {
local level=$1
local message=$2
local datetime=$(date '+%Y-%m-%d %H:%M:%S')
case $level in
NORMAL)
echo "$datetime - NORMAL: $message" >> "$LOG_FILE"
;;
ERROR)
[ $LOG_LEVEL -ge 2 ] && echo "$datetime - ERROR: $message" >> "$LOG_FILE"
;;
INFO)
[ $LOG_LEVEL -ge 3 ] && echo "$datetime - INFO: $message" >> "$LOG_FILE"
;;
DEBUG)
[ $LOG_LEVEL -ge 4 ] && echo "$datetime - DEBUG: $message" >> "$LOG_FILE"
;;
esac
}
# Function to find a unique name if there's a conflict
find_unique_name() {
local base=$(basename "$1")
local dir=$(dirname "$1")
local count=0
local new_base=$base
log DEBUG "Finding unique name for $1"
while [ -e "$dir/$new_base" ]; do
count=$((count + 1))
new_base="${base%.*}"_"$count.${base##*.}"
done
log DEBUG "Unique name found: $dir/$new_base"
echo "$dir/$new_base"
}
# Function to move files and handle errors
move_file() {
local src=$1
local dst_dir=$2
log DEBUG "Attempting to move file $src to directory $dst_dir"
if [ ! -d "$dst_dir" ]; then
mkdir -p "$dst_dir" || { log ERROR "Failed to create directory $dst_dir."; exit 1; }
fi
local dst=$(find_unique_name "$dst_dir/$(basename "$src")")
mv --backup=t "$src" "$dst" >> "$LOG_FILE" 2>&1 || { log ERROR "Failed to move $src to $dst."; exit 1; }
log INFO "Moved $src to $dst."
}
# Function to move all files within a directory
move_directory() {
local src_dir=$1
local dst_dir=$2
log DEBUG "Attempting to move directory $src_dir to $dst_dir"
mkdir -p "$dst_dir" || { log ERROR "Failed to create directory $dst_dir."; exit 1; }
mv --backup=t "$src_dir" "$dst_dir" >> "$LOG_FILE" 2>&1 || { log ERROR "Failed to move $src_dir to $dst_dir."; exit 1; }
log INFO "Moved directory $src_dir to $dst_dir."
}
# Main noscript starts here
log INFO "Task ID: $TASK_ID Completed."
log DEBUG "SOURCE_FILE is $SOURCE_FILE"
if [ "$NUM_FILES" -eq 0 ]; then
log INFO "No file to move for Task ID $TASK_ID."
exit 0
fi
# Determine the source and destination directories
SOURCE_DIR=$(dirname "$SOURCE_FILE")
DESTINATION_DIR=$(echo "$SOURCE_DIR" | sed "s,$DOWNLOAD,$COMPLETE,")
log DEBUG "SOURCE_DIR is $SOURCE_DIR"
log DEBUG "DESTINATION_DIR is $DESTINATION_DIR"
# Check if SOURCE_FILE is part of a directory and move the entire directory
if [ "$(basename "$SOURCE_DIR")" != "$(basename "$DOWNLOAD")" ]; then
log DEBUG "Moving entire directory as the source file is within a subdirectory"
move_directory "$SOURCE_DIR" "$COMPLETE"
else
log DEBUG "Moving a single file $SOURCE_FILE"
move_file "$SOURCE_FILE" "$DESTINATION_DIR"
fi
log NORMAL "Task ID $TASK_ID completed successfully."
log NORMAL "Moving $SOURCE_FILE completed successfully."
exit
I’ve developed a noscript that moves completed downloads from Aria2. I’m seeking feedback on potential improvements. You can review the noscript here: [GitHub](https://github.com/macg4dave/aria_move).
I’m considering replacing the mv command with rsync and refining the variable management. Are there any other enhancements or best practices I should consider?
#!/bin/sh
# Variables for paths (no trailing slashes)
DOWNLOAD="/mnt/World/incoming"
COMPLETE="/mnt/World/completed"
LOG_FILE="/mnt/World/mvcompleted.log"
TASK_ID=$1
NUM_FILES=$2
SOURCE_FILE=$3
LOG_LEVEL=1 # 1=NORMAL, 2=NORMAL+INFO, 3=NORMAL+INFO+ERROR, 4=NORMAL+DEBUG+INFO+ERROR
# Function to log messages based on log level
log() {
local level=$1
local message=$2
local datetime=$(date '+%Y-%m-%d %H:%M:%S')
case $level in
NORMAL)
echo "$datetime - NORMAL: $message" >> "$LOG_FILE"
;;
ERROR)
[ $LOG_LEVEL -ge 2 ] && echo "$datetime - ERROR: $message" >> "$LOG_FILE"
;;
INFO)
[ $LOG_LEVEL -ge 3 ] && echo "$datetime - INFO: $message" >> "$LOG_FILE"
;;
DEBUG)
[ $LOG_LEVEL -ge 4 ] && echo "$datetime - DEBUG: $message" >> "$LOG_FILE"
;;
esac
}
# Function to find a unique name if there's a conflict
find_unique_name() {
local base=$(basename "$1")
local dir=$(dirname "$1")
local count=0
local new_base=$base
log DEBUG "Finding unique name for $1"
while [ -e "$dir/$new_base" ]; do
count=$((count + 1))
new_base="${base%.*}"_"$count.${base##*.}"
done
log DEBUG "Unique name found: $dir/$new_base"
echo "$dir/$new_base"
}
# Function to move files and handle errors
move_file() {
local src=$1
local dst_dir=$2
log DEBUG "Attempting to move file $src to directory $dst_dir"
if [ ! -d "$dst_dir" ]; then
mkdir -p "$dst_dir" || { log ERROR "Failed to create directory $dst_dir."; exit 1; }
fi
local dst=$(find_unique_name "$dst_dir/$(basename "$src")")
mv --backup=t "$src" "$dst" >> "$LOG_FILE" 2>&1 || { log ERROR "Failed to move $src to $dst."; exit 1; }
log INFO "Moved $src to $dst."
}
# Function to move all files within a directory
move_directory() {
local src_dir=$1
local dst_dir=$2
log DEBUG "Attempting to move directory $src_dir to $dst_dir"
mkdir -p "$dst_dir" || { log ERROR "Failed to create directory $dst_dir."; exit 1; }
mv --backup=t "$src_dir" "$dst_dir" >> "$LOG_FILE" 2>&1 || { log ERROR "Failed to move $src_dir to $dst_dir."; exit 1; }
log INFO "Moved directory $src_dir to $dst_dir."
}
# Main noscript starts here
log INFO "Task ID: $TASK_ID Completed."
log DEBUG "SOURCE_FILE is $SOURCE_FILE"
if [ "$NUM_FILES" -eq 0 ]; then
log INFO "No file to move for Task ID $TASK_ID."
exit 0
fi
# Determine the source and destination directories
SOURCE_DIR=$(dirname "$SOURCE_FILE")
DESTINATION_DIR=$(echo "$SOURCE_DIR" | sed "s,$DOWNLOAD,$COMPLETE,")
log DEBUG "SOURCE_DIR is $SOURCE_DIR"
log DEBUG "DESTINATION_DIR is $DESTINATION_DIR"
# Check if SOURCE_FILE is part of a directory and move the entire directory
if [ "$(basename "$SOURCE_DIR")" != "$(basename "$DOWNLOAD")" ]; then
log DEBUG "Moving entire directory as the source file is within a subdirectory"
move_directory "$SOURCE_DIR" "$COMPLETE"
else
log DEBUG "Moving a single file $SOURCE_FILE"
move_file "$SOURCE_FILE" "$DESTINATION_DIR"
fi
log NORMAL "Task ID $TASK_ID completed successfully."
log NORMAL "Moving $SOURCE_FILE completed successfully."
exit
GitHub
GitHub - macg4dave/aria_move: This noscript automates the process of moving downloaded files or directories from a designated incoming…
This noscript automates the process of moving downloaded files or directories from a designated incoming folder to a completed folder once the download is finished using aria2c. - macg4dave/aria_move
Read Upwork request data
For URL
https://www.upwork.com/nx/search/jobs/?nbs=1&page=5&per\_page=50
In my Firefox Web Developer Tools the request to https://www.upwork.com/api/graphql/v1 is made and the type is 'application/x-thrift+json'.
The request headers include:
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Also I see the JSON response in the Web Developer tab.
But when I copy the request as curl and paste it to command line it returns gibberish which can be either a binary gzip archive or some thrift data (I have no idea what thrift is). piping to gunzip and using curl --compressed option gives an error saying it's not an archive data. How can I read that response and see JSON ?
https://redd.it/1f7vo0e
@r_bash
For URL
https://www.upwork.com/nx/search/jobs/?nbs=1&page=5&per\_page=50
In my Firefox Web Developer Tools the request to https://www.upwork.com/api/graphql/v1 is made and the type is 'application/x-thrift+json'.
The request headers include:
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Also I see the JSON response in the Web Developer tab.
But when I copy the request as curl and paste it to command line it returns gibberish which can be either a binary gzip archive or some thrift data (I have no idea what thrift is). piping to gunzip and using curl --compressed option gives an error saying it's not an archive data. How can I read that response and see JSON ?
https://redd.it/1f7vo0e
@r_bash
Quitting a Script without exiting the shell
I wrote a simple bash noscript that has a series of menus made with
The problem is that
I guess I could put the whole noscript in a
What’s the proper way to quit a noscript? Thanks for your time!
UPDATE:
I’m a clown. I had only ever run
I really appreciate all the quick responses!
https://redd.it/1f85r2h
@r_bash
I wrote a simple bash noscript that has a series of menus made with
if statements. If a user selects an invalid option, I want the noscript to quit right away.The problem is that
exit kills the terminal this noscript is running in, & return doesn’t work since it’s not a “function or sources noscript.”I guess I could put the whole noscript in a
while loop just so I can use break in the if else statements, but is there a better way to do this?What’s the proper way to quit a noscript? Thanks for your time!
UPDATE:
I’m a clown. I had only ever run
exit directly from a terminal, & from a sourced noscript. I just assumed it always closed the terminal. My bad.I really appreciate all the quick responses!
https://redd.it/1f85r2h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
AutoPilot - it's siimple | Automate the setup of a new system with ease
# AutoPilot - It's simple.
[**AutoPilot**](https://github.com/Noam-Alum/AutoPilot/) is a free-to-use, [well documented](https://docs.alum.sh/AutoPilot/Introduction.html) bash noscript (for both **Debian** and **RHEL** related operating systems) written by [me](https://www.linkedin.com/in/noam-alum/) meant to automate the process of setting up a new system.
It uses [YAML](https://en.wikipedia.org/wiki/YAML) for its configuration file, so it is very easy to set up, and you can create numerous configuration files for different occasions. (I like to call them *"Profiles"* 🙃)
https://preview.redd.it/hc8790ev8nmd1.png?width=269&format=png&auto=webp&s=480f775b873bad386577d30c524fcfefc7b6ca64
**Current available directives (**[v1.0.0](https://github.com/Noam-Alum/AutoPilot/releases/tag/v1.0.0)**):**
* [SELinux](https://docs.alum.sh/AutoPilot/directives/SELinux.html)
* [Users](https://docs.alum.sh/AutoPilot/directives/Users.html)
* [Run\_Lines](https://docs.alum.sh/AutoPilot/directives/Run_Lines.html)
* [Installed\_packages](https://docs.alum.sh/AutoPilot/directives/Installed_packages.html)
* [Plugins](https://docs.alum.sh/AutoPilot/directives/Plugins.html)
* [Network\_Configuration](https://docs.alum.sh/AutoPilot/directives/Network_Configuration.html)
* [Environment\_configuration](https://docs.alum.sh/AutoPilot/directives/Environment_configuration.html)
* [Cronjobs](https://docs.alum.sh/AutoPilot/directives/Cronjobs.html)
* [Repo](https://docs.alum.sh/AutoPilot/directives/Repo.html)
* [Time](https://docs.alum.sh/AutoPilot/directives/Time.html)
**Use cases:**
|**Use Case**|**Denoscription**|
|:-|:-|
|**Educational Institutions**|Educational institutions can leverage AutoPilot to quickly deploy standardized environments for students and faculty.|
|**Development Environments**|Developers can use New System to configure their development machines with the necessary programming languages, libraries, frameworks, and tools.|
|**Personal Use**|Individuals who frequently set up new machines or reinstall their operating systems can benefit from AutoPilot by automating the setup process.|
|**Testing and QA**|AutoPilot automates test environment setup, providing quality assurance teams and testers with consistent, repeatable configurations and necessary tools.|
|**Temporary Setups**|For temporary or event-based setups like trade shows or conferences, AutoPilot quickly prepares machines with the required software and settings, making deployment and management easier for short periods.|
|**Rescue and Recovery**|When a system needs recovery or rebuilding after a failure, AutoPilot automates software reinstallation and settings reconfiguration, reducing the time to restore it to its original state.|
|**Company Deployment**|A company can use AutoPilot to quickly configure new machines, ensuring consistent software and settings. This includes installing productivity tools, setting up configurations, and applying security policies.|
|**OS Migration**|When switching operating systems, AutoPilot automates setup of applications, configurations, and settings, ensuring a smooth transition and minimizing manual reinstallation and reconfiguration.|
|**System Formatting**|If you need to format and reinstall your operating system, AutoPilot handles post-installation setup. It automates software installation, configuration, and personalization, helping you get back to work faster.|
>I hope someone could find this helpful 😁, if you want to request a new feature you can do that [here](https://github.com/Noam-Alum/AutoPilot/issues/new?assignees=Noam-Alum&labels=feature+request&projects=&template=feature-request.md&noscript=Feature+request+%7C+%5Bfeature+request+short+denoscription%5D).
**Links:**
* [GitHub](https://github.com/Noam-Alum/AutoPilot/)
* [Documentation](https://docs.alum.sh/AutoPilot/Introduction.html)
* [Contribute](https://github.com/Noam-Alum/AutoPilot/blob/main/CONTRIBUTING.md)
https://redd.it/1f88k58
@r_bash
# AutoPilot - It's simple.
[**AutoPilot**](https://github.com/Noam-Alum/AutoPilot/) is a free-to-use, [well documented](https://docs.alum.sh/AutoPilot/Introduction.html) bash noscript (for both **Debian** and **RHEL** related operating systems) written by [me](https://www.linkedin.com/in/noam-alum/) meant to automate the process of setting up a new system.
It uses [YAML](https://en.wikipedia.org/wiki/YAML) for its configuration file, so it is very easy to set up, and you can create numerous configuration files for different occasions. (I like to call them *"Profiles"* 🙃)
https://preview.redd.it/hc8790ev8nmd1.png?width=269&format=png&auto=webp&s=480f775b873bad386577d30c524fcfefc7b6ca64
**Current available directives (**[v1.0.0](https://github.com/Noam-Alum/AutoPilot/releases/tag/v1.0.0)**):**
* [SELinux](https://docs.alum.sh/AutoPilot/directives/SELinux.html)
* [Users](https://docs.alum.sh/AutoPilot/directives/Users.html)
* [Run\_Lines](https://docs.alum.sh/AutoPilot/directives/Run_Lines.html)
* [Installed\_packages](https://docs.alum.sh/AutoPilot/directives/Installed_packages.html)
* [Plugins](https://docs.alum.sh/AutoPilot/directives/Plugins.html)
* [Network\_Configuration](https://docs.alum.sh/AutoPilot/directives/Network_Configuration.html)
* [Environment\_configuration](https://docs.alum.sh/AutoPilot/directives/Environment_configuration.html)
* [Cronjobs](https://docs.alum.sh/AutoPilot/directives/Cronjobs.html)
* [Repo](https://docs.alum.sh/AutoPilot/directives/Repo.html)
* [Time](https://docs.alum.sh/AutoPilot/directives/Time.html)
**Use cases:**
|**Use Case**|**Denoscription**|
|:-|:-|
|**Educational Institutions**|Educational institutions can leverage AutoPilot to quickly deploy standardized environments for students and faculty.|
|**Development Environments**|Developers can use New System to configure their development machines with the necessary programming languages, libraries, frameworks, and tools.|
|**Personal Use**|Individuals who frequently set up new machines or reinstall their operating systems can benefit from AutoPilot by automating the setup process.|
|**Testing and QA**|AutoPilot automates test environment setup, providing quality assurance teams and testers with consistent, repeatable configurations and necessary tools.|
|**Temporary Setups**|For temporary or event-based setups like trade shows or conferences, AutoPilot quickly prepares machines with the required software and settings, making deployment and management easier for short periods.|
|**Rescue and Recovery**|When a system needs recovery or rebuilding after a failure, AutoPilot automates software reinstallation and settings reconfiguration, reducing the time to restore it to its original state.|
|**Company Deployment**|A company can use AutoPilot to quickly configure new machines, ensuring consistent software and settings. This includes installing productivity tools, setting up configurations, and applying security policies.|
|**OS Migration**|When switching operating systems, AutoPilot automates setup of applications, configurations, and settings, ensuring a smooth transition and minimizing manual reinstallation and reconfiguration.|
|**System Formatting**|If you need to format and reinstall your operating system, AutoPilot handles post-installation setup. It automates software installation, configuration, and personalization, helping you get back to work faster.|
>I hope someone could find this helpful 😁, if you want to request a new feature you can do that [here](https://github.com/Noam-Alum/AutoPilot/issues/new?assignees=Noam-Alum&labels=feature+request&projects=&template=feature-request.md&noscript=Feature+request+%7C+%5Bfeature+request+short+denoscription%5D).
**Links:**
* [GitHub](https://github.com/Noam-Alum/AutoPilot/)
* [Documentation](https://docs.alum.sh/AutoPilot/Introduction.html)
* [Contribute](https://github.com/Noam-Alum/AutoPilot/blob/main/CONTRIBUTING.md)
https://redd.it/1f88k58
@r_bash
GitHub
GitHub - Noam-Alum/AutoPilot: Automate the setup of a new system with ease, AutoPilot - it's simple.
Automate the setup of a new system with ease, AutoPilot - it's simple. - Noam-Alum/AutoPilot
Help parsing a text file
I'm writing a noscript that needs to parse a text file and call another noscript depending on what it finds.
This is an example of the text file data:
555555:
- x.x.x.x/32
- x.x.x.x/24
- x.x.x.x/32
555556:
555557:
555558:
- x.x.x.x/32
- x.x.x.x/24
555559:
555560:
From the above file, think of each number as a VM. I need to run one noscript on each VM without trailing IPs, and the same noscript plus a different noscript on the VMs with trailing IPs.
Grabbing the VMs without IPs is easy enough, of course. I'm having a hard time determining how I'll grab each VM with IPs and all their IPs (since the number of IPs vary wildly). I thought I'd bounce this off the interwebz and see if anyone could give me an idea or three?
Maybe a while loop for when I find IPs but even though I'm at a loss thinking how I'll grab only those IPs with the corresponding VM.
https://redd.it/1f8bgpi
@r_bash
I'm writing a noscript that needs to parse a text file and call another noscript depending on what it finds.
This is an example of the text file data:
555555:
- x.x.x.x/32
- x.x.x.x/24
- x.x.x.x/32
555556:
555557:
555558:
- x.x.x.x/32
- x.x.x.x/24
555559:
555560:
From the above file, think of each number as a VM. I need to run one noscript on each VM without trailing IPs, and the same noscript plus a different noscript on the VMs with trailing IPs.
Grabbing the VMs without IPs is easy enough, of course. I'm having a hard time determining how I'll grab each VM with IPs and all their IPs (since the number of IPs vary wildly). I thought I'd bounce this off the interwebz and see if anyone could give me an idea or three?
Maybe a while loop for when I find IPs but even though I'm at a loss thinking how I'll grab only those IPs with the corresponding VM.
https://redd.it/1f8bgpi
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
single quote (apostrophe) in filename breaks command
I have a huge collection of karaoke (zip) files that I'm trying to clean up, I've found several corrupt zip files while randomly opening a few to make sure the files were named correctly. So I decided to do a little noscript to test the zips, return the lines with "FAILED" and delete them. This one-liner finds them just fine
But theres the glaring error "sh: 1: Syntax error: Unterminated quoted string" every time grep matches one, so I can't get a clean output to use to send to rm. I've been digging around for a few days but haven't found a solution
https://redd.it/1f8fmv5
@r_bash
I have a huge collection of karaoke (zip) files that I'm trying to clean up, I've found several corrupt zip files while randomly opening a few to make sure the files were named correctly. So I decided to do a little noscript to test the zips, return the lines with "FAILED" and delete them. This one-liner finds them just fine
find . -type f -name "*.zip" -exec bash -c 'zip -T "{}" | grep FAILED' \;But theres the glaring error "sh: 1: Syntax error: Unterminated quoted string" every time grep matches one, so I can't get a clean output to use to send to rm. I've been digging around for a few days but haven't found a solution
https://redd.it/1f8fmv5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
SSID's not showing up when trying to echo them.
Hi all,
I am trying to write a noscript that will make connecting to wifi on my openbsd laptop easier. I have the noscript mostly complete; however, I get the error:
./wifiscanner.sh: line 7: echo "SSID: $ssid": command not found
here is my noscript so far:
#! /usr/local/bin/bash
doas ifconfig iwn0 up
for i in $(ifconfig iwn0 scan |
sed '/iwn0/,/network/d' |
sed -e 's/.*nwid\(.*\)chan.* /\1/' |
sed '/""/d' |sed '/0x0/d' | tr -d '""'|
head -n 10| while read ssid;
do
ssid_var="${ssid}"
'echo "SSID: $ssid"' :**
done) ;
do
read -p "Select your SSID: (e.g, ssid1) " ssid_name
done
read -p "Enter your WPA key: " WPAkey
echo "ifconfig iwn0 nwid ${ssid_name} wpakey ${WPAkey}"
without the apostrophes nothing shows up. How do I go about fixing this?
Thank you
https://redd.it/1f8kh5h
@r_bash
Hi all,
I am trying to write a noscript that will make connecting to wifi on my openbsd laptop easier. I have the noscript mostly complete; however, I get the error:
./wifiscanner.sh: line 7: echo "SSID: $ssid": command not found
here is my noscript so far:
#! /usr/local/bin/bash
doas ifconfig iwn0 up
for i in $(ifconfig iwn0 scan |
sed '/iwn0/,/network/d' |
sed -e 's/.*nwid\(.*\)chan.* /\1/' |
sed '/""/d' |sed '/0x0/d' | tr -d '""'|
head -n 10| while read ssid;
do
ssid_var="${ssid}"
'echo "SSID: $ssid"' :**
done) ;
do
read -p "Select your SSID: (e.g, ssid1) " ssid_name
done
read -p "Enter your WPA key: " WPAkey
echo "ifconfig iwn0 nwid ${ssid_name} wpakey ${WPAkey}"
without the apostrophes nothing shows up. How do I go about fixing this?
Thank you
https://redd.it/1f8kh5h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Running via cronjob, any way to check the server load and try again later if it's too high?
I'm writing a noscript that I'll run via cronjob at around 1am. It'll take about 15 minutes to complete, so I only want to do it if the server load is low.
This is where I am:
attempt=0
# server load is less than 3 and there have been less than 5 attempts
if (( $(awk '{ print $1; }' < /proc/loadavg) < 3 && $attempt < 5))
then
# do stuff
else
# server load is over 3, try again in an hour
let attempt++
fi
The question is, how do I get it to stop and try again in an hour without tying up server resources?
My original solution: create an empty text file and touch it upon completion, then the beginning of the noscript would look at the
Is there a better way?
https://redd.it/1f90a2b
@r_bash
I'm writing a noscript that I'll run via cronjob at around 1am. It'll take about 15 minutes to complete, so I only want to do it if the server load is low.
This is where I am:
attempt=0
# server load is less than 3 and there have been less than 5 attempts
if (( $(awk '{ print $1; }' < /proc/loadavg) < 3 && $attempt < 5))
then
# do stuff
else
# server load is over 3, try again in an hour
let attempt++
fi
The question is, how do I get it to stop and try again in an hour without tying up server resources?
My original solution: create an empty text file and touch it upon completion, then the beginning of the noscript would look at the
lastmodified time and stop if the time is less than 24 hours. Then set 5 separate cronjobs, knowing that 4 of them should fail every time.Is there a better way?
https://redd.it/1f90a2b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Sending mail through bash, is mailx still the right option?
I'm writing a noscript that will be run via cronjob late at night, and I'd like for it to email the results to me.
When I use
If mailx is still right, does the
This is the man for mailx:
NAME
mailx - send and receive Internet mail
SYNOPSIS
mailx -BDdEFintv~ -s subject -a attachment -c cc-addr -b bcc-
addr -r from-addr -h hops -A account -S vari-
able[=value] to-addr . . .
mailx -BDdeEHiInNRv~ -T name -A account -S variable[=value] -f
name
mailx -BDdeEinNRv~ -A account -S variable[=value] -u user
https://redd.it/1f8zn0x
@r_bash
I'm writing a noscript that will be run via cronjob late at night, and I'd like for it to email the results to me.
When I use
man mail, the result is mailx. I can't find anyone talking about mailx in the last decade, though! Is this still the best way to send mail through bash, or has it been replaced with someone else?If mailx is still right, does the
[-r from_address] need to be a valid account on the server? I don't see anything about it being validated, so it seems like it could be anything :-O Ideally I would use root@myserver.com, which is the address when I get other server-related emails, but I'm not sure that I have a username/password for it.This is the man for mailx:
NAME
mailx - send and receive Internet mail
SYNOPSIS
mailx -BDdEFintv~ -s subject -a attachment -c cc-addr -b bcc-
addr -r from-addr -h hops -A account -S vari-
able[=value] to-addr . . .
mailx -BDdeEHiInNRv~ -T name -A account -S variable[=value] -f
name
mailx -BDdeEinNRv~ -A account -S variable[=value] -u user
https://redd.it/1f8zn0x
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Any way to tell if noscript is ran via command line versus cron?
Inside of a bash noscript, is there a way to tell whether the noscript was ran via command line versus crontab?
I know that I can send a variable, like so:
# bash foo.sh bar
And then in the noscript, use:
if [ $1 -eq "bar" ]
then
# it was ran via command line
fi
but is that the best way?
The goal here would be to printf results to the screen if it's ran via command line, or email them if it's ran via crontab.
https://redd.it/1f93hp3
@r_bash
Inside of a bash noscript, is there a way to tell whether the noscript was ran via command line versus crontab?
I know that I can send a variable, like so:
# bash foo.sh bar
And then in the noscript, use:
if [ $1 -eq "bar" ]
then
# it was ran via command line
fi
but is that the best way?
The goal here would be to printf results to the screen if it's ran via command line, or email them if it's ran via crontab.
https://redd.it/1f93hp3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community