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
Related Posts with Thumbnails