Posts

Showing posts with the label bash

Fun with Bash Double Brackets, Regular Expressions, Case Matching, and Digits

Image
After some quick searching and not finding the answer, I decided to write this up for my own reference. My original inquiry was how do I form a double-bracketed if branch statement, using "=~" to check a variable against a regular expression for upper OR lower case of a specific search string in bash. After some working it out, I think I got it. See below. For instance, in the example script below, the user is asked to answer yes or no, the value entered is then checked to "loosely" match a predefined value. In this case, yes/y (with any combination of case) will match the Regular Expression. This example points out how to formulate your bracketed regular expression to match any variations in case (or even a single character answer, e.g., y OR n). There are differences with the bracketed use of regular expressions compared to how grep uses them, I'm finding. Like, notice in the experimental script below, how single quotes are not used in the bracketed ...

Simple Bash Script to Reverse Your Name and Output it

Just a quick script to reverse some input, using Bash and the FOSS "rev" program. It's amazing how easy it is to manipulate things with Bash. I love it! Bash script version: #!/bin/bash #Simple script to reverse an input name echo "Enter your name";read 'myname' echo "Your name spelled backwards is: $( echo $myname | rev )" exit 0 One-liner version: echo -n "what is your name?";read name;echo "$name" |rev Or how about this more ridiculous example (one that doesn't use the "rev" program): #!/bin/bash #Simple script to reverse an input name   echo -n "Enter your name:"   read myname   numChars=$(echo -n "$myname" |wc -c)   revname=   while [ $numChars -gt 0 ]   do       revname=$revname$(echo -n "$myname"|cut -b$numChars)       numChars=$(expr $numChars - 1)  done echo "Your name spelled backwards is: $revname" exit 0 Ridic...

Simple Bash Script to Remove Clearcase Views (experimental)

Image
So I just wanted to take a minute to say how awesome GNU Bash is, and that you can do a great many things with it. One of those things you can do is run commands from the cross-platform-compatible(mostly) IBM Rational Clearcase cleartool. Since I was working on cleaning up some old user views, I thought I'd just make a quick writeup on a script for helping with this task. I did it because I like writing scripts in Bash and I'm working (very often) to get better at it. Please note, the script is experimental, and just meant for tinkering purposes. That said, I can't be held responsible for any damage you do to your systems as a result of using this script. The script takes a parameter of the username. The script will search for views that are owned by the username, and will de-register, de-tag them. As for deleting the actual files at the view path, that part is NOT done by this script. Instead, the script will record the server name and view path into a file named...

Sample Script to Report /home Directory Usage

Image
So, awhile back, I created this simple script to monitor usage of the /home directory on a GNU/Linux server. I've been working on it a bit more lately and I figured it's time to share it. The script is configurable to check for "certain" files in a user's directory (i.e., .iso, .mp3, .etc), has a minimum reporting threshold setting, and outputs to a file. Keep an eye out for crazy numbers because I'm seeing differences in the way the find and du commands report, depending on their versions. So if you see some weird reporting situation, let me know so I can address the problem. Using user quotas on server would probably be just as effective but what can I say, I like a challenge. Note: before you light your torches, I don't claim to be a bash scripting expert (not yet anyways). So if anyone has any "constructive" criticism, please feel free to leave a comment. The script is GPL (of course), so please feel free to use any part of it (or the...