- Rares Aioanei
- Programming & Scripting
Some Linux tools does not properly work with files which include spaces in their names. This simple bash for loop will remove white space from file names and rename/move for all files in the given directory.
Very often I need to upload some files to my web server from a command line. entering a user name and password, changing directory can be little tedious work. Here is a small bash script which make this work easier. This script first defines a variables such as hostname of the ftp server, username and password and then it creates ftp session and uploads file into your selected directory:
Here is a small bash script to test a hard drive transfer speed. It should be take as an approximation. The speed value is taken from Linux dd command output. One way to test your hard drive speed is to use hdparm command:
This is a simple skeleton of a bash countdown script. The script takes two arguments . Here are some examples of its usage:
./bash-countdown.sh -m 90
./bash-countdown.sh -d "Mar 23 2036"
./bash-countdown.sh -d 21:06
./bash-countdown.sh -d 21:06:45
This simple perl script will print your external IP address assigned by you internet provider ( great for someone with dynamic IP address ).
First, we download a html file from ipchicken.com and then phrase this file to match for IP address in format X.X.X.X using regular expression.
Next, the script removes all unnecessary characters and prints your external IP address on the terminal. Lastly, the script removes previously downloaded index.html file.
The following bash script allows user to check for domain name availability using a whois utility ( Domain hijacking made easy ). User needs to only supply single or multiple keywords and the script checks domain availability for each keyword+domain-label. See below for a sample output.
Please feel free to add more generic domain labels into the list. However, test your whois server on what it returns if domain is available as not all whois servers return the exact string. I have tested only domains which are currently in the bash script below. When you get a string which your whois server returns when domain name is available, add it to the script's grep line starting with prefix"|". The chances are that if you add new domain name label the script will just work, but if not you know what to do.
Insert following lines into a file called check-domain-availability.sh
Here are two ways on who to redirect both standard output and standard error to same file in bash. First the official a recommended way:
printf '%s\n%\n' "Hello bash" > FILE 2>&1
now easier unofficial way:
Sometimes it is needed to check what user is executing the bash script and whether the user supplied all required arguments:
This Perl programming tutorial is a great scripting guide to help you fully understand Perl script. Find Perl tutorials and programming examples to master your knowledge of Perl Scripting.
First you need to find out where is your bash interpreter located. Enter the following into your command line:
$ which bash
This article provides few simple scripts to scan and monitor network using combination of bash and ping command. Obviously, these scripts are no match to a full monitoring dedicated software like nagios but they could be useful for a small home brand networks, where implementing sophisticated monitoring system can become an overhead.
In this example the bash script will scan network for hosts attached to an IP address 10.1.1.1 - 255. The script will print message Node with IP: IP-address is up if ping command was successful. Feel free to modify the script to scan your hosts range.
When writing a bash scripts most of us by default use echo command as means to print to standard output stream. echo is easy to use and mostly it fits our needs without any problem. However, with simplicity very often comes limitation. This is also the case with echo command. Formatting an echo command output can be a nightmare and very often impossible task to do.
The solution to this can be a good old friend of all C/C++ the “printf” tool. printf can be just as easily implemented into a bash script is it is used with C/C++ programs. This article describes some basics of printf along with practical examples: