Subsribe to our RSS Feed
Featured Sites
test DiggThis
31st

Dec.

Comments:

Disabled

Simple bash Alias

This post is a sort of follow up to the previous one however for a different purpose. So imagine that you have to create passwords on a regular basis, for your end users or what not. Obviously you want them to be unique, and strong. In addition to the "Randpass" script that I have added to the site you can create a simple alias in your .bashrc to simplify creating these passwords.

Edit your .bashrc with your favorite text editor (vim,vi,nano,gedit etc..) and add the following line to the very end of the file alias pass="curl -s http://dev.linux-servers.net/index.php?id=randpass"
Here is an example of what your .bashrc should look similar to after the changes: # .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions
alias pass="curl -s http://dev.linux-servers.net/index.php?id=randpass"

Once this is done run the command "bash -l" or close then re-open your shell. Now you should be able to run the command "pass" and it will output a password for you to use. The output should look like this: user@localhost:~$ pass
xehiqo4tdw
user@localhost:~$


26th

Dec.

Comments:

Disabled

Copy local IP to clipboard

The following script is pretty simple, and has very limited functionality, however is a good example of how to send information to your clipboard assuming you are using your linux installation as a desktop.

So what does the script do? It display's your internal, and external IP address, then copy's the internal IP to your clip board so that you can easily paste it. Enough said, here it is: #!/bin/bash

# Place local IP address into a variable
LIP=`ifconfig eth0 | grep "inet addr:" | cut -d':' -f2,4 | sed 's/.+Bcast:/\//g' | awk -F"Bcast:" '{print $1}'`

# Place external IP into a variable
WIP=`curl -s http://linux-servers.net/ip.php`

# display the IP's
echo "LOCAL IP: ${LIP}"
echo "WAN IP: ${WIP}"

# send local IP to clip board
echo ${LIP} | xsel -i

Download Link

26th

Dec.

Comments:

Disabled

Basic bash function - Example

This is a basic bash "function". There is not much to it but functions are essential for writing clean, and properly structured code which helps in development, troubleshooting, and understanding of the script.

#!/bin/bash

# Define the function "function_name"
function function_name(){

# Execute your command
echo "Hello World!"

}

# Call the function
function_name

As you can see there is not much to it.. Functions can be very helpful in breaking down your code into segments which makes it much easier to manage, and in the event that you are going to be writing a very long script - will make the code much easier to work with. | Download Link