Questions tagged [bash]

BASH is the GNU Bourne Again SHell, the successor to the classic Unix Bourne sh (shell). It's the default shell for various GNU systems.

Filter by
Sorted by
Tagged with
3
votes
1answer
16 views

Bookmarking directories

When working on a large codebase, I often need to switch between deeply nested directories quickly. To make my life easier, I came up with a bookmarking script. ...
3
votes
1answer
21 views

Deployment Automatization for docker builds, kubernetes deploys and secret injection [Bash]

I've written a small script that automates the tasks I previously did manually for deploying onto our kubernetes clusters and I am quite happy with the results I have, but I do think that what my ...
2
votes
1answer
18 views

git Create Tree from Arbitrary Directory (works in bare repository)

I made a script for a project I'm working on to create a tree object from a filesystem directory, without any working tree operations (can be run in a bare repository). The tree can be inserted into (...
2
votes
1answer
24 views

Script to move images into year and month folder

This following code searches for jpg files of size larger than 500 KB. Its purpose is to move/cp files, depending on their EXIF data, into folders that correspond ...
1
vote
1answer
38 views

Remap ls to honor .hidden files

I wrote this code in my .bashrc to remap ls to honor .hidden files. I'm pretty new to shell/bash scripting, so I feel like this is not the most performant way to handle this, and it has some ...
4
votes
2answers
43 views

Command to measure CPU time and RAM usage of process while making sure it does not go over certain ressource limitation

I found some old code of mine and am trying to see if it can be improved. The goal is to write a command that measures a process's CPU time and RAM peak usage and kills the process if it exceeds a ...
2
votes
0answers
24 views

BASH script to obfuscate android/meterpreter payloads

I have written a little script that does a pretty good job of obfuscating android/meterpreter payloads. It will generate payloads or used supplied msf payloads while also injecting a custom icon. The ...
11
votes
2answers
495 views

Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so: <...
3
votes
1answer
31 views

Syncing GitHub repositories local, remote and forks

It's a simple bash script but I'm hoping for feedback, advice and examples on how to improve the script and code. Can you guide me how to put more checks in the code and more if possible? This code: ...
7
votes
1answer
37 views

Bash script to encode images in base64 and generate a CSS file from them

These are the first lines of code I've ever written. I've been interested in the idea of learning to program for quite a while, but never really pulled the trigger, and now I've been playing around ...
2
votes
0answers
36 views

Code to backup the history file in Linux

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file; I just wrote it and I've tested it and it almost works. This was the ...
1
vote
1answer
66 views

Bash Code to backup the history file in Linux [closed]

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file, I just wrote it. The code is supposed to do this: Backup my ...
9
votes
2answers
785 views

Count line of code for a JavaScript project

Here is my bash script that I just wrote to count line of code for JavaScript project. It will list number of: Comment lines Blank lines All lines Here is my script: ...
2
votes
2answers
52 views

Looking to shorten method of parsing arguments in BASH

I have here a working method of parsing input arguments however it seems redundant. I would like to shorten this code so it doesn't appear so repetitive. ...
3
votes
1answer
41 views

checksum hash verification functions for bash scripts

just a little script, or a bit of a template of one that I used to submit an assignment. I believe it all works fine, I just wanted to give it to other people, and get some feedback on it; maybe make ...
2
votes
1answer
26 views

shell library for Debian package releases

This is a bash library intended to be used in a CI/CD pipeline to make finding the next release number for a Debian package semi-automatic. I figured out how to ...
5
votes
2answers
52 views

Smart way to shorten the current working directory in pure Bash

I'm trying to create a shell prompt that displays the $PWD in a "smart" way. I want to display the top two directories rather than the full path. If ...
4
votes
1answer
62 views

Removing duplicate field entries from sorted csv data

Given the following input (cat i.txt), I want to remove duplicate field entries in each of the first three columns and none of the others. ...
4
votes
1answer
59 views

Shell script to calculate the total space consumed by a user by file-size

I'm working with a small bash code which is working fine but i'm just looking if there is better way to formulate this, In this code i'm looking for the Files between year 2002 and 2018 on the 7th ...
4
votes
1answer
69 views

Bash script to setup new Debian installs - follow-up

I have this bash script I've been working on and I have updated it. I was hoping for some advice and/or input on the code. This script is run directly after a fresh install of ...
2
votes
1answer
102 views

Create Apache2 virtualhost, Mysql db & user. CLI tool and GUI on top of it

Review for optimization, code standards, missed validation. What's in this version: Rewritten, instead of large complex script - few tools with each own task. Solid CLI tool and GUI script on top of ...
5
votes
1answer
84 views

Pure bash program for auto-filling a template file (Part 2)

This is my rewrite of the program posted here, based on janos's comments. I also added the ability to read from stdin. I've also included a test script. I wanted something lightweight I could ...
3
votes
1answer
49 views

Pure bash program for auto-filling a template file with ENV variables

Goal of Program Consider a template file template.txt with double brace variables, intended to be replaced by values: ...
5
votes
1answer
68 views

Batch upload users to nextcloud on docker with bash csv

I have this bash script that adds users to NextCloud from a csv file. It expects to be run from the same directory as the docker-compose.yml file. I'm pretty new to bash scripting and I'm wondering ...
3
votes
1answer
27 views

Local backup bash

The following code copy a complete folder (that has 3 folders inside), then check if errors are generated and send email if there's errors, the it proceeds to create 3 different tar files and finally ...
1
vote
1answer
21 views

Revised media ingest script

link to original question: Simple media ingest script As per answers I have refactored my code and would like to get feedback on the current structure. The purpose of this tool is to allow someone ...
4
votes
2answers
40 views

Simple media ingest script

Trying to script a simple command line tool for ingesting media to a target location following a structured naming convention. It's functional in its current state but I'd like to know if there are ...
6
votes
2answers
1k views

Backup with Hanoi Strategy

I want your suggestions about this shell script. I use it to backup some configurations on my home media server. What improvements would you do? Keep in mind, I want to optimize space and speed and ...
4
votes
2answers
55 views

Append a note to one of three files based on user choice

The user selects one of the three categories then makes a note on that selection. Then the note is appended and saved to the appropriate list. It took me four hours to write this. I'm trying to learn ...
9
votes
5answers
169 views

Disallow `rm` to remove `*`

Note: If you googled this by the title of this question, don't use this script unless you know what it is supposed to do. This is a script in bash 3+ that I have ...
2
votes
2answers
70 views

Create Apache virtualhost, MySQL db and user, install option - desktop shortcut for GUI version

Review for optimization, code standards, missed validation and dependency checks. Review version 3. What's new: apply previous code review input arguments and validation MySQL management (optional) ...
2
votes
1answer
69 views

Bash on Synology - Delete recycle bin entries over X days old

Synology NASs have a Task Scheduler that allows you to schedule deletion of files over X days old from recycle bins. This feature isn't working for me–running the task results in no files being ...
1
vote
1answer
43 views

bash script - Create virtualhost on development server (ver 2)

Review compatibility, readability, good code standards, security. This is for development server, where webmaster uses GUI fo IDE and fine way to create quickly apache2 virtualhost using GUI but ...
6
votes
1answer
66 views

Simple bash script creates apache2 virtualhost config for subdomain

Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost". Tested on Ubuntu, but should work where ...
0
votes
1answer
25 views

Refactoring with many duplicates using Bash [closed]

I have a curl based working bash script, but I have many duplicates on the "CURL" body. How do I improve it efficiently to eliminate duplications? ...
9
votes
2answers
546 views

Bash script to truncate subject line of incoming email

I'm going to put this script into production in a mail server /etc/aliases file: we have a system that receives email but the subject line must be limited to a certain size. The proposed usage in the ...
1
vote
1answer
21 views

Install a Python package based on active_gpu or version [closed]

I have the following code, is there a way to optimize it/reduce the code? ...
0
votes
2answers
60 views

Bash Script for file auditing, push information to server and be able to view in a web page

Edit: The goal of this Question was only seeking code review and guidance in learning or tips for improvement. I apologize if that was not clear or aligned properly with the goals of this forum. ...
3
votes
2answers
46 views

Bash - Passing arguments with “$@” to either 'sudo su' or 'sh'

I have a server where shell commands to the supervisor-service must be executed by the specific user lx. I have written a bash function that does exactly that. <...
3
votes
2answers
51 views

Creating remote directories in a bash script via ssh (with error trapping)

I'd like to create directories on a remote VM, but only if they do not exist. What's more, if creating the directory results in an error (exit status != 0) I'd like the script to exit as well, or at ...
1
vote
1answer
40 views

Bash function to produce variants of images at 2X and 3X resolutions

I use ImageMagick to crop image, encapsulate the related code to functions. Here is the code: ...
3
votes
1answer
17 views

Tagging the directories and switching between them by tags - follow-up (Part 2/2: business logic)

This is the bash script responsible for changing the directories via textual tags. (See here the entire project.) dt_script ...
1
vote
1answer
27 views

Mac Bash: how to combine the open and str subtract to one line code? [closed]

new to bash , I use the following code to open the super folder with a file path. function openUp(){ cd $(echo $1 | sed 's@\(.*\)/.*@\1@' ); open .. } like ...
1
vote
2answers
30 views

Bash script to find included files in C code

I've got the following shell script (let say get_includes.sh): ...
3
votes
1answer
52 views

Bash script to backup a LAMP server

I wrote a bash script for backing up my LAMP server. To be honest that's my first experience in bash so I want to ask you for help in its improvement. ...
0
votes
2answers
47 views

“command preprocessing” with bash - string parsing and handling pipes [closed]

The following is a bash script named wrapper.sh: ...
4
votes
2answers
64 views

Upload a directory, in parallel, to an artifact repository

This code uploads an entire directory and allows for its reparenting on a remote server (an artifact repository). Three concerns: Copying the files locally takes a lot of space. Ideally, I could use ...
4
votes
1answer
66 views

Select second field in text table with shell script

I am writing a bash script to mount openshift service accounts into kubernetes objects. The right secret to use is highlighted in this text: $ oc describe sa sa-...
3
votes
2answers
88 views

Removing commented dead code without removing the legitimate comments

This question is the real question asked on StackOverflow. I'm here to review my answer and see how can I optimize it. Here is the answer text: This is a basic approach, but it proposes a proof of ...