Add Current PATH to crontab
Are you sick of your cron job failing because you are not explicitly listing the full path of everything in your shell script? Here’s how to fix it!
Your script works when you run it from the console but fails in cron.
Your crontab doesn’t have the right . . . → Read More: Add Current PATH to crontab
How to create a bash script that deletes itself
This script will delete itself via the shred command (secure deletion) when it exits
#!/bin/bash # # Author: Steve Stonebraker # Date: August 20, 2013 # Name: shred_self.sh # Purpose: securely self-deleting shell script # http://brakertech.com/self-deleting-bash-script currentscript=$0 # function that is called when the script exits . . . → Read More: self deleting bash script
Recently I needed to calculate the starting and ending memory addresses of an IOS application (in order to dump it). As a result i needed to figure out how to add two hex addresses. Here’s what I discovered.
In this case we are adding 0x4f000 and 0×2000
$ printf “0x%X\n” $(( 0x4f000+0×2000 )) . . . → Read More: Howto Add Hex Numbers via Command Line
Here’s my bash cheat sheet:
Tests Combining [ condition ] && action; # action executes if condition is true. [ condition ] || action; # action executes if condition is false. Filesystem related tests
We can test different filesystem related attributes using different condition flags as follows:
[ -f $file_var ]: Returns true if the . . . → Read More: Bash Cheat Sheet
Goal: Whitelist an Entire Country with ipset For this article i’ll be referencing the github repository I set up at
https://github.com/ssstonebraker/braker-scripts/tree/master/working-scripts/ipset We have a few files there, specifically: * cidr_to_ipset.sh (a script to create an ipset ruleset) * Some example CIDR blocks for Italy (IT.txt), Spain (ES.txt), Great Britian (GB.txt), USA (US.TXT) * sample_firewall.txt (example . . . → Read More: Whitelist Entire Country with ipset
Recently I tried passing a bash variable to perl command in bash script, it didn’t end well.
Troy Engel from http://tacticalvim.wordpress.com/ was nice enough to point out the issue:
use sed instead of perl for what you need; it’s simpler, faster and uses the bash variables easily.
I set up a test script /home/someuser/test.sh to show:
. . . → Read More: passing bash variable to perl command in bash script
Objective: Prep dev httpd.conf for production
Remove jenkins virtual host entry (which starts with a comment line “#Start Jenkins”) Replace .dev with nothing (ex: www.dev.example.com becomes www.example.com) Replace debug with error (ex: Loglevel debug becomes Loglevel error) Sed to remove lines after match
In this example we will use sed delete all lines after . . . → Read More: sed delete all lines after
to add multiple users to a system and force them to change their password upon login try the following script:
Redhat # for name in someuser anotheruser yetanotheruser; do useradd $name; echo ‘password’ | passwd –stdin $name; chage -d 0 $name; done
The above script will add three users to the system (someuser . . . → Read More: redhat add multiple users
I’ve created a Bash Server Backup Script that will backup your MySQL databases (each database separately in to .sql and .xml files) and your main directories (/var/log, /var/www/html, /etc, /home, /root) to a timestamped directory. Feel free to re-use or hack up however you’d like
Here’s my Bash Server Backup Script: Download the script here
. . . → Read More: Bash Server Backup Script
This script will allow you to see the top user agents, urls, IPs for your log files:
Script name: ls-httpd
#!/bin/bash # Usage # ls-httpd type count # Eg: # ls-httpd url 1000 # will find top URLs in the last 1000 access log entries # ls-httpd ip 1000 # will find top IPs . . . → Read More: parse apache access log entries to find top user agents, top urls and top IPs