Showing posts with label Shell. Show all posts
Showing posts with label Shell. Show all posts

## Wednesday, 5 September 2018

### Create Alias Command with Parameter in Linux

"Alias" - A shortcut for a command or set of commands

Linux OS provides the facility to have alias command to keep the long and frequent command to very few keystrokes, May be I am being a more cryptic with the lots of jargon words, let's try to understand this way -

When you execute a command "ll" (double Ele) in Linux prompt, it will return the result which is the same as "ls -l" because most of the modern linux os have this alias command (ll) for "ls -l" which is quick and easy.  You can add your customize command in ".bashrc" (dot bashrc) in case of  BASH shell or ".kshrc" in case of KORN shell.

How To:
alias pcs = 'ps -ef'  # this will create an alias named pcs which is equivalent to "ps -ef"

As we can see, we can create lots of alias of frequent commands needed in our day to day work, but avoid the alias which modifies/delete system files.

Now, Coming back to the Original Topic,  Can we create an alias which accepts the arguments, Answer is YES, lets check it our How To --

How To create ALIAS which accept command line parameter:

• Create a script which will accept the argument and do the task, such as -
= =

• Create an alias for this script as -
==

• How to use this alias -
==

and voilà !! we are done, Now you can add so many scripts as alias which accept the parameters, Please share here if you have created something useful for you.

Like the below page to get update

## Wednesday, 31 May 2017

### Remove ctrl-M character from all files within Directory #iLoveScripting

Continuing our journey on #iLoveScripting,..............
This script will do the same task as "clnM.sh" but this will accept Directory Path as an input rather than the filename. It will iterate through each file within given directory and remove all Ctrl-M characters.

If you are unable to see the Script, Please find it here - LINK

## Tuesday, 30 May 2017

### Remove ctrl-M character from file #iLoveScripting

This is my first post under #iLoveScripting which will have lots of shell script which are helping me in my day to day task and sharing here for all guys for easing their work as well.

The very magical script, which I have use, is "clnM.sh". This script is remove the ctrl-M characters (^M) from your windows file.

Usage:  clnM.sh <FILE>

If you are unable to see the Script, Please find it here - LINK

## Sunday, 21 May 2017

### dos2unix - A script to convert DOS to LINUX formatting #iLoveScripting

dos2unix - a simple filter to convert text files in DOS format to UNIX/LINUX end of line conventions by removing the carriage return character(\r).  This will leave the newline character(\n) which unix expects.

Usgae:
dos2unix [file1] :  Remove DOS End of Line (EOL) char from file1, write back to file1
dos2unix [file1] [file2] : Remove DOS EOL char from file1, write to file2
dos2unix -d [directory] : Remove DOS EOL char from all files in directory

## Monday, 16 January 2017

### Linux Shell Utilities

This shell script can be called from any other shell script as ". UXUtils.sh" and any of the functions can be called to use. Even the funcions can be kept in the .profile and called through calling .profile.

The following functions are provided here:
to_lower               [ Change the upper case word to lower case.]
to_upper              [ Change the lower case to upper case. ]
check_numeric    [ Checks whether an input is a number. ]
check_decimal     [ Checks whether an input is a floating point number. ]
check_null            [ Checks for NULLs. ]
string_length        [ Evaluates the length of a string. ]
concatAll              [ Concats 'n' number of strings. ]
token_n                [ Returns the n'th token of a string.]

How To:
This is how you have to call this script to utilize any function in your current script.

In the caller script:
----------------------
# Calling UXUtils.sh
. UXUtils.sh

x1="COUMPTER"
RV=to_lower $x1 RV1=string_length$x1

Find the complete script here -

## Wednesday, 12 October 2016

### Script to Auto Compress the System Log Files

This Script is originally written by "Andy Welter" to compress the linux system log files. I have modified it to work better. You can find it below (modified version) -

Script Usage:
logroll [-compress|-nocompress]

$logroll -compress # compress the log files and move to archive directory logroll -nocompress # Move the file to archive directory with compressing it =================================================================== =================================================================== ## Tuesday, 19 April 2016 ### Best book for Linux Shell Scripting - Intermediate User Today, I am gonna share my secret of Linux Scripting. The book, shared below, is core responsible for my shell scripting technique and ease. I love the tips n tricks, tweaks or many more or you can say I simply love this book :-) So here it is -- Hoping you all also get benefitted by this. For Intermediate Linux Shell Scripting users, this book provide all the tips and tricks which we can include in out script to make it work more efficient way. Mastering Unix Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus by Randal K. Michael Link: http://www.amazon.in/dp/0470183012 == == ## Wednesday, 3 February 2016 ### Python Points #9 - Tuples ## Sunday, 31 January 2016 ### Create a Daemon to Trace New Processes Description The following code can be used to create a daemon that will watch for processes that show up in the "ps -ef" output with certain characteristics. When it identifies such processes, it will attach to them with a trace utility (i.e. strace, truss, tusc... you must change the code to reflect this on whatever platform this is run on). The tool does not follow these processes with a fork since it will trace any children that contain the same "ps -ef" characteristics. This makes it useful for tracing DS PX programs that contain rsh since truss's fork flag (i.e. "-f") blocks the rsh from executing. Usage The script below should be saved to a file such as /tmp/tracer.sh and given rwx permissions. The trace utility name that is appropriate for your platform should be altered in the "ps -ef" command and in the "for" loop. The script would then be run using this syntax: /tmp/tracer.sh <search string> As mentioned above, the search string can be any value that would appear in the "ps -ef" output. Such values might be a user id, particular time, a command, or arguments to a command. The fifth and eight lines of this script gather lists of all commands to be traced and then attempts to remove commands that should be ignored. If you find too many processes getting traced, identify why it was selected and then alter these two lines by adding a "grep -v" to the list of items bieng ignored. ## Friday, 22 January 2016 ### Shell Script for getting lines after and before of search String Sometime when we search some text string in Unix environment we need those strings also which come before or after that searched string. This below small shell-script gives same output and return output in one file depends on user choice that how many no. of lines user wants to print after and before any searched string. This script take input as search string and no. of line you want to print before and after search result line and give output in search.txt ## Tuesday, 15 December 2015 ### How to use Universe Shell (uvsh) in DataStage? In DataStage Administration, we have to use datastage command line (universe shell) to get the information directly from the datastage universe database. While accessing it from command line what novice admin do is - $ uvsh
This directory is not set up for DataStage.
Would you like to set it up(Y/N)?   
Confused ? What to do ?

Always answer that question "no", it means you're in the wrong place.
Always launch "uvsh" or "dssh" from one of two places - $DSHOME or inside a project directory. For the latter you're good to go, for the former you'll need to LOGTO your project name before you issue any sql. How to use UVSH? ## Entered into the$DSHOME
$cd$DSHOME

## Sourced the dsenv file
$. dsenv ## Change directory to the project directory.$ LOGTO <project_name>

## Run uvsh command
DSHOME/bin/uvsh

## Sourced the dsenv file
$.$DSHOME/dsenv
$LOGTO <project_name> ## Run dssh command$ \$DSHOME/bin/dssh
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.332586407661438, "perplexity": 7963.171257930221}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-30/segments/1563195526153.35/warc/CC-MAIN-20190719074137-20190719100137-00341.warc.gz"}