linux poison RSS
linux poison Email
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
Related Posts with Thumbnails