BASH is the Bourne Again SHell, the successor to the classic Unix sh (shell). It's the official shell of GNU.

learn more… | top users | synonyms

2
votes
1answer
13 views

Reading options from .cfg file

I have a bash script that reads a config file with key/value pairs and uses these values to modify the functioning of other scripts correspondingly. Example .cfg file: ...
14
votes
7answers
304 views

Extracting the classpath entries from a jar file's manifest

Sometimes I need to search for dependencies in the classpath entries in the manifest of jar files. A jar manifest with classpaths looks like this: ...
6
votes
1answer
40 views

Monitor Downloads folder and sort files as they are downloaded

I have written my first shell script that uses inotify-tools to monitor my Downloads directory. What I intend to do with the script is that, as soon as a file is ...
4
votes
3answers
29 views

Loop through all virtualhost log files and run goaccess on each file

So I have multiple websites running under apache2 virtualhost - and I wanted to use GoAccess to process the access.log for each site. The directory structure is ...
4
votes
2answers
45 views

Team git commit cleaner

I cleaned a big repository for my team with this Python code. My goal was for every developer in my team to check if some bad email are in the commit, and replace the information by the good one. I ...
3
votes
1answer
33 views

Changing cuts to sed for parsing dates from apache log (common log file)

Would switching my cuts below to SED improve performance? I am trying to get a per date count of requests for the last two weeks from a server log. The script runs, but slowly (comes in around 14 ...
0
votes
1answer
40 views

Is this iptables firewall bash script good? [closed]

I'm learning to use iptables to implement it in my company software. The goal is either to prevent the major attacks and to have good speed transferring files (ssh and ftp). Can you help me to improve ...
1
vote
1answer
29 views

Screen timeout/lock script

This is a script I made while having trouble with xautolock and dimming of the screen right before locking it. I would like some tips for making it a bit more robust and to know of any disadvantages ...
2
votes
1answer
46 views

Dovecot user add & delete bash script

I learn BASH scripting occasionally from time to time, now I am working on a simple bash script that serves to maintain dove-cot user database. The general purpose of the script is able to list, add ...
5
votes
1answer
44 views

Bash script for Git & VSS interop

I have been slowly evolving some code for Git and VSS interop based on a quest I started a while ago And the code is now working, some parts have been updated without test (such as the init) and I am ...
1
vote
1answer
63 views

Simple Bash backup script - follow-up

As a follow up to a previous question, linked here, I have revised the code and developed what I believe to be a better solution. In summary, the script should backup all files in a particular ...
3
votes
1answer
121 views

Simple Bash log backup script

I have developed the following script to zip and then remove all files with "*.log" extension in the file name that were modified yesterday. It's definitely not 100% at the moment. For example, it ...
4
votes
1answer
39 views

Rename files to all lowercase letters

I use this Bash script to rename specified files to all lowercase letters: ...
4
votes
3answers
174 views

Script to generate templated PHP code

I've created a script to create a module in our MVC framework The structure of the module is like this (for this example, the module is called test ...
2
votes
1answer
29 views

Bash-based MySQL inventory scanner

I am trying to create a bash-based inventory scanner, and was wondering if there is anything 'glaringly' incorrect about my syntax or usage. I was hoping I could get some feedback on: bash ...
3
votes
1answer
37 views

Can this bash shell script that checks for rvm ruby versions be improved?

As it is going to be used as part of some automation and not just at the command line I was wondering if it could be improved at all. Improve would mean any of: handle sad cases better handle ...
8
votes
1answer
403 views

Securely delete a file

I am trying to write a script to securely delete a file. What I am intending to do is to pad the file with /dev/zero once, and then with /dev/urandom three times and then delete the file. For now the ...
2
votes
1answer
31 views

Bash script for reviewing .pdf articles

I wrote a bash script for reviewing scientific articles. It adds a blank page for notes and creates a new landscape file. I'm sure it can be made better code wise. Any suggestions? ...
3
votes
1answer
22 views

Renaming and moving files in a subdirectory with an index and the folder name

I'm putting together a script to take .mp4 files organized into folders that described the video (eg. cat) and I'd like to do the following: rename them with the folder name and a number move the ...
4
votes
1answer
41 views

Find-grep-sed for project-wide search & replace

I always forget how to do this efficiently with Vim's arglist. Drawing inspiration from a post over at Stack Overflow, I wrote a Bash function to perform a project-wide search & replace. It does ...
2
votes
1answer
32 views

Bash Script - File Comment out & Notate

I have been writing my own Bash Scripts for a little while now. I am getting a better comprehension of it and I would like to start refining my code to be more elegant. I have recently developed this ...
3
votes
1answer
51 views

Bash archiving script

I inherited a script at work the other day. I know very little about the command line in general but I'm not entirely new to programming. I am using this as an opportunity to learn... Very little ...
5
votes
1answer
47 views

An atexit for Bash

I wrote the following atexit implementation for Bash ...
3
votes
1answer
44 views

Unit testing a bash script manipulating the working directory path

bd is a bash script to conveniently jump multiple directory levels up from the current working directory instead of a tedious and possibly inaccurate ...
3
votes
2answers
166 views

Checking percentage of free memory using top and awk

The following Awk code was created in order to verify if free memory from the top command is less than 20% of the total. I've noticed that I actually do not need the ...
6
votes
3answers
125 views

Back up or restore home directory

I am currently trying to learn bash scripting and I've made a script that backs up or restores my home folder. My main question is whether my code is readable or very messy. I would love to learn to ...
6
votes
1answer
358 views

Bash script for getting geolocation (latitude, longitude and country code)

I have a bash script, where I need to get the user's geolocation (latitude, longitude and country code). If a GPS device is present, I use gpspipe. But a lot of laptops/computers don't have GPS ...
2
votes
1answer
32 views

Controller web interface security

I'm designing a web interface to a controller for my school's bell. Are there any security flaws in this code? The source code is available here. Front End: ...
5
votes
1answer
74 views

Updating an Nginx config file for SSL

This script updates a settings in ssl config file for Nginx. I generate DHEC key and then update the Nginx SSL file to that location. I also give an option for the user through arguments if they want ...
6
votes
5answers
235 views

Mounting multiple partitions on a disk

Is it possible to improve the code of this bash script? ... or should I just use another language? (If so, which one would fit the best the situation, according to you?) Here is the code (simplified, ...
2
votes
1answer
34 views

Bash script for tagging the current git workspace including uncommitted changes

I use the following script to autotag the current workspace while building even if there are changed (not committed) files: ...
6
votes
1answer
455 views

Using /proc/stat to calculate CPU usage

Inspired by this question: To calculate the total CPU usage as a percentage I wrote the following bash script (as an answer) to calculate the CPU usage for a (configurable) period over all CPU cores ...
12
votes
2answers
541 views

To calculate the total CPU usage as a percentage

I have been developing the below method to calculate the CPU usage of a Linux system at a point in time, as a percentage of the total number of cores available in the system. ...
4
votes
1answer
37 views

Script to fix audio level

I need to fix and maintain the master volume in PulseAudio (so that I don't blow up my speakers). E.g. call gfaaudio -v 25 to fix volume at 25%. Is there a cleaner ...
4
votes
2answers
56 views

A better way of always dumping Gedit out of Terminal?

I use terminal alot, so it was frustrating to me to deal with gedit's inconsistent behavior between having a window open and when one was not. I ended up searching around, and finding a way of getting ...
3
votes
1answer
119 views

Bash functions to run/manage MySQL, Redis, Sidekiq, Rails server

I'm working with a Rails app that requires a few layers of infrastructure to run: MySQL, Redis, Sidekiq, and (of course) the Rails server. I wrote some functions to help me manage the various servers ...
7
votes
3answers
842 views

Extracting data from text file in bash using awk, grep, head and tail

I've been writing bash script on and off, with pretty good results in terms of getting the job done. However, I'm worried that my script might be very ugly, as I am a beginner. I'm looking for advice ...
5
votes
2answers
70 views

Function autoloading in bash

I'm wondering if anyone can code review my code below. That's the core code of my little framework for bash in GitHub. ...
5
votes
2answers
84 views

File handling script

This is my first bash script so I ask to you to say what you think. The script must check every directory and if it finds a pdf file in this directory: move all the pdf files to parent directory, ...
6
votes
1answer
187 views

Git commit-msg URL shortener

I have just written my first git hook script. It is very simple that simply finds any URLs in the commit message and uses the Google URL shortener to rewrite the URL nicely. it is located here. I ...
4
votes
1answer
37 views

Generic Makefile

I decided to setup a generic makefile to compile SFML programs, as I'm going to be making a bunch of small apps over the next few weeks playing around with it. I'm still new to writing makefiles ...
2
votes
1answer
38 views

Cheat Code Scraper

During breaks, I find myself playing Emerald version a lot and was tired of having to use the school's slow wifi to access the internet. I wrote a scraper to obtain cheat codes and send them to my psp ...
4
votes
3answers
120 views

Git script that fast forward merges and deletes the old branch

This script fast forward merges a branch and then deletes the old one. I normally run it like this: git m master feature Here's a link to the gist. ...
5
votes
2answers
46 views

OS testing script

This is a script I made for testing a simple operating system. It assembles the source and creates a boot image, then It automates the configuration of a Virtual Box machine. ...
5
votes
2answers
1k views

Small bash script to start and stop named services

I've been working on ubuntu since many years but not quite familiar with bash scripting. My development tools involve servers like nginx and apache, the mysql database and beanstalkd. Obviously, I ...
4
votes
2answers
69 views

Filter shell script to find lines that contain all specified patterns

I wrote a script that does the following: Run another script on the system Filter the output to find lines that contain ALL of the given patterns Pipe the output to a second script on the system I ...
7
votes
2answers
45 views

Trash Filing System

This is a script (function) to be added to a bashrc. The purpose is to not actually remove files, but rather to send them to a trash folder for safe keeping. I was tired of deleting important files. ...
2
votes
1answer
31 views

IPtables for webserver with ssh

I've had a bit of help but I'm still a bit unsure. I have an nginx webserver with SSH only required. I wrote this rule set based on information I found on the internet: ...
0
votes
2answers
18 views

${} shell substitution using output of another program [closed]

I want to collect total RSS used by all foo processes and pass it to quux script as an argument. ...
5
votes
1answer
113 views

Building/installing BASH script - does it need major changes?

I'm writing a bash script that has these goals: to build a node program from sources to install the built program on Ubuntu Linux to allow the user to rebuilt from most recent sources to add a ...