Category Archives: Shell Scripting

13Apr/14

Linux Shell Scripting – Functions

How do I create a shell script function using Bash under UNIX / Linux operating systems?

Functions are nothing but small subroutines or subscripts within a Bash shell script. You need to use to break up a complex script into separate tasks. This improves overall script readability and ease of use. However, shell function cannot return value. They return a status code.

All functions must be declared before they can be used.

function welcome(){
  Commands
}

OR

 
welcome(){
 Commands
 return $TRUE
}

You can call function by typing its name:

 
welcome

Continue reading

09Nov/13

debug1: read_passphrase: can’t open /dev/tty:

I have faced this error when I was trying to setup a remote script execution via SSH, on my CentOS box. Initially I have made sure that the user as which I run the particular script can access the particular file about which it complaints it cannot read. But permission looks fine. After a quick googling, I could fix it by adding the remote host hey to the known_hosts file of the local user I try ( simple try “ssh remoteuser@remoteIP” as local user ) and then I was able to run the remote script via SSH fine.

07Nov/13

Mail Queue Management Exim

Main things we need while managing a Mail Queue is removing spam mails, Frozen mails, Bounce mails, Queue force rerun etc.

I am adding some commonly used commands below for managing Exim Servers

To get the total number of mails in the queue

# exim -bpc

To list the mails in the queue

# exim -bp

Used to remove the message from queue with Exim Id : 1VcjOL-0002YV-8g

# exim -Mrm 1VcjOL-0002YV-8g
 Continue reading 
07Oct/13

Linux Shell Scripting – An Introduction

Linux Shell Scripting

Scripts are collections of commands that are stored in a file. The shell can read this file and act on the commands as if they were typed at the keyboard. The shell also provides a variety of useful programming features to make your scripts truly powerful.

Write a simple shell script

Use an editor software to write the script. The following is the simplest “Hello World” program.

#!/bin/sh
# My first script
echo "Hello World!"

and save the above script to the file name “myScript.sh”

We can use any name for saving the script. but here I am using “.sh” extension for my script, since the shell used here is “/bin/sh”. Also it will help us to identify the scripts from a other files and folders. Continue reading