linux poison RSS
linux poison Email
0

Perl Script: Convert any given string To-Lower or To-Upper case

Below is simple perl script which converts any given string to Upper or to-Lower case ...
Here, we have used the perl Escape Sequence ( \U \L \E)

\U -- Convert all following letters to Uppercase
\L -- Convert all following letters to Lowercase
\E -- Ends the effect of \L, \U or \Q

Feel free to copy and use this code ...

Source: cat case-conversion.pl
#!/usr/bin/perl

print "Enter the string: ";
$var = <STDIN>;

print "To uppercase: \U${var}\E \n";
print "To lowercase: \L${var}\E \n";

Output: perl case-conversion.pl
Enter the string: LinuxPoison
To uppercase: LINUXPOISON
To lowercase: linuxpoison


Read more
0

An indispensable ebook for every Linux administrator

"Linux® Quick Fix Notebook- Free 696 Page eBook"

Instant access to precise, step-by-step solutions for every essential Linux administration task from basic configuration and troubleshooting to advanced security and optimization.

If you're responsible for delivering results with Linux, Linux® Quick Fix Notebook brings together all the step-by-step instructions, precise configuration commands, and real-world guidance you need. This distilled, focused, task-centered guide was written for sysadmins, netadmins, consultants, power users...everyone whose livelihood depends on making Linux work, and keeping it working.

This book's handy Q&A format gives you instant access to specific answers, without ever forcing you to wade through theory or jargon. Peter Harrison addresses virtually every aspect of Linux administration, from software installation to security, user management to Internet services--even advanced topics such as software RAID and centralized LDAP authentication. Harrison's proven command-line examples work quickly and efficiently, no matter what Linux distribution you're using. Here's just some of what you'll learn how to do:

 * Build Linux file/print servers and networks from scratch
 * Troubleshoot Linux and interpret system error messages
 * Control every step of the boot process
 * Create, manage, secure, and track user accounts
 * Install, configure, and test Linux-based wireless networks
 * Protect your network with Linux iptables firewalls
 * Set up Web, email, DNS, DHCP, and FTP servers

And much more...

By Peter Harrison. Published by Prentice Hall. Part of the Bruce Perens' Open Source Series.

Download your free copy of "Linux® Quick Fix Notebook" - here


Read more
3

Bash Script: Script to check internet connection

Below is simple bash script to test the Internet connection using wget utility.
Feel free to copy and use this script

Source: cat internet_connection.sh
#!/bin/bash

HOST=$1
WGET="/usr/bin/wget"

$WGET -q --tries=10 --timeout=5 $HOST
RESULT=$?

if [[ $RESULT -eq 0 ]]; then
        echo "Connection made successfully to $HOST"
else
        echo "Fail to make connection to $HOST"
fi

Output:
./internet_connection.sh http://yahoo.com
Connection made successfully to http://yahoo.com

./internet_connection.sh http://yahosssss.com
Fail to make connection to http://yahosssss.com


Read more
0

Bash Script: Commenting out the block of code using here document

Many times it required to comment out the huge block of code for debugging purpose and it is very annoying to put the "#" tag before each and every line of this code

Below shell script shows how to comment out the block of code using here document (: <<'COMMENT')

Source: cat comment_block.sh
#!/bin/bash

echo "statement before comment."
: <<'COMMENT'
echo "This is inside the comment block and will not get printed"
a=0
b=20
echo $((b/a))
echo "No error"
COMMENT

echo "This is after the comment block."
exit

Output: ./comment_block.sh
statement before comment.
This is after the comment block.


Read more
2

Bash Script: Transfer files through FTP from within script

Below shell script demonstrate the usage of FTP operation from within the bash script, feel free to copy and use this script:

Source: cat autoftp.sh
#!/bin/bash

if [ $# -ne 1 ]; then
        echo "Please provide the file path for ftp operation."
        exit
fi

USERNAME=linuxpoison
PASSWORD=password
FILENAME="$1"
FTP_SERVER=ftp.foo.com
echo "Starting the ftp operation ...."

ftp -n $FTP_SERVER <<Done-ftp
user $USERNAME $PASSWORD
binary
put "$FILENAME"
bye
Done-ftp

echo "Done with the transfer of file: $FILENAME"
exit

Output: ./autoftp.sh log.tar.gz
Starting the ftp operation ....
Done with the transfer of file: log.tar.gz


Read more
0

Free White Paper - The Trend from UNIX to Linux in SAP Data Centers

"The Trend from UNIX to Linux in SAP® Data Centers"

Linux has arrived in large SAP data centers, and the SAP customer base shows significant momentum in migrating from UNIX to Linux. To explain this development, the following white paper will provide information about which customers are migrating from UNIX to Linux, in terms of size and industrial sector, and why they are migrating.

The paper will provide statistical information on the market shares of originating UNIX flavors, and information on the distribution of source and target databases. It will present a model that compares the cost of UNIX implementations with that of Linux implementations, and it will demonstrate that Linux is ready for business-critical SAP implementations. It will also show that significant savings can be realized by migrating SAP system landscapes from UNIX to Linux.

Download your free copy of White paper (The Trend from UNIX to Linux in SAP® Data Centers) - here

Read more
3

Bash Script: Convert File from DOS to UNIX format

Common problem! If you need to exchange text files between DOS/Windows and Linux, be aware of the "end of line" problem. Under DOS, each line of text ends with CR/LF (Carriage return/Line feed), with LF under Linux. If you edit a DOS text file under Linux, each line will likely end with a strange--looking `M' character;

Below is simple shell script which converts the files in DOS format to Unix format
Feel free to copy and use this code

Source: cat dos_unix.sh
#!/bin/bash

if [ $# -ne 1 ]; then
        echo "Please provide the path of a valid DOS file"
        exit
fi

if [ ! -f "$1" ]; then
        echo "Cannot access file: $1"
        echo "Don't play, provide the vaild file."
        exit
fi

DOSFILE=$1
UNIXFILE=output.unix
CR='\015'

tr -d $CR < $DOSFILE > $UNIXFILE

echo "Done with the conversion"
echo "New output file is: $UNIXFILE"
exit

Read more
0

Bash Script: Get the Information about the caller of the function (backtrace)

Caller Returns  the  context  of  any active subroutine call (a shell function or a script executed with the . or source builtins). caller displays the line number and source filename of the current subroutine call.  If a non-negative integer is supplied as expr,  caller displays  the line number, subroutine name, and source file corresponding to that position in the current execution call stack.  This extra information may be used, for example, to print a stack trace. 

Below is simple bash script which demonstrate the usage of caller ...
feel free to copy and use this code

Source: cat caller.sh
#!/bin/bash

foo() {
        caller 0
        echo "In function: foo"
}

echo "Outside of the function"

goo() {
        echo "In function: goo"
        foo
}

goo

Output: ./caller.sh
Outside of the function
In function: goo
13 goo ./caller.sh
In function: foo

Read more
0

Bash Script: Write debugging information to /var/log/messages

logger is a shell command interface to the syslog system log module, it appends a user-generated message to the system log (/var/log/messages). You do not have to be root to invoke logger.

Below is the simple bash script to log the debugging information to /var/log/message
Feel free to copy and use the below code

Source: cat logger.sh
#!/bin/bash

echo -n "Enter your username: "
read username

logger -i "Username $username started the script"

echo -n "Enter your Password: "
read password

# This is just an sample for comparing the password
if [ "$password" = "linuxpoison" ]; then
        echo "welcome $username"
        logger -i "Authentication successful for $username."
else
        echo "your Username or password does not match"
        logger -i "Authentication failed for $username."
fi

Read more
0

Bash Script: Set the timeout for reading the user input

If TMOUT set to a value greater than zero, TMOUT is treated as the default timeout for the read builtin.  The select command terminates if  input does  not arrive after TMOUT seconds when input is coming from a terminal. 

In an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt.  Bash terminates after waiting for that number of seconds if input does  not arrive.

Below is the bash script which explains the above concept ...
Feel free to copy and use this script

Source: cat timeout.sh
#!/bin/bash

TMOUT=5
echo -n "Enter you username: "
read username

if [[ -z $username ]]; then
        # No username provide
        username="Not Set"
        echo "Timeout, Run this script again and set your valid username..."
fi


Output: ./timeout.sh
Enter you username: Timeout, Run this script again and set your valid username...
Read more
0

Bash Script: Running part of the script in restricted mode

If Bash is started with the name rbash, or the --restricted or -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. A restricted shell behaves identically to bash with the exception that the following are disallowed or not performed:

 * Changing directories with the cd built-in.
 * Setting or unsetting the values of the SHELL, PATH, ENV, or BASH_ENV variables.
 * Specifying command names containing slashes.
 * Specifying a filename containing a slash as an argument to the . built-in command.
 * Specifying a filename containing a slash as an argument to the -p option to the hash built-in command.
 * Importing function definitions from the shell environment at startup.
 * Parsing the value of SHELLOPTS from the shell environment at startup.
 * Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’ redirection operators.
 * Using the exec built-in to replace the shell with another command.
 * Adding or deleting built-in commands with the -f and -d options to the enable built-in.
 * Using the enable built-in command to enable disabled shell built-ins.
 * Specifying the -p option to the command built-in.
Read more
0

Free eBook - The GNU/Linux Advanced Administration

"The GNU/Linux Advanced Administration"


The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.

In this ebook "The GNU/Linux Operating System", the main contents are related with system administration. You will learn how to install and configure several computer services, and how to optimize and synchronize the resources using GNU/Linux.

The topics covered in this 500+ page eBook include Linux network, server and data administration, Linux kernel, security, clustering, configuration, tuning, optimization, migration and coexistence with non-Linux systems. A must read for any serious Linux system admin.

Download your free copy of "The GNU/Linux Advanced Administration" - here


Read more
1

Free eBook - HA Solutions for Windows, SQL, and Exchange Servers

"HA Solutions for Windows, SQL, and Exchange Servers".

How to protect your company's critical applications by minimizing risk to disasters with high availability solutions.

When total data loss is possible, the absence of a disaster recovery program can put a business at risk. Although disasters are inevitable and, to a degree, unavoidable, being prepared for them is completely within your control.

Increasingly, IT has become the focal point of many companies' disaster planning. Creating a program to preserve business continuity and recover from disaster is one of the central value propositions that an IT department can contribute to an organization.

Download you free HA Solutions for Windows, SQL, and Exchange Servers eBook - here


Read more
Related Posts with Thumbnails