Help needed for understanding a function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed for understanding a function
# 1  
Old 03-06-2010
Help needed for understanding a function

There is a function called start:

Code:
start()
{
echo -n $"Sending Startup Email: "
echo "${RESTARTBODY}" | mutt -s "${RESTARTSUBJECT}" ${EMAIL}
RETVAL=$?

if [ ${RETVAL} -eq 0 ]; then
touch ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}

Can anyone explain what the bold part of the function means?
# 2  
Old 03-06-2010
Quote:
Originally Posted by proactiveaditya
There is a function called start:

(Code indented for easier comprehension.)
Quote:
Code:
start()
{
  echo -n $"Sending Startup Email: "
  echo "${RESTARTBODY}" | mutt -s "${RESTARTSUBJECT}" ${EMAIL}
  RETVAL=$?

  if [ ${RETVAL} -eq 0 ]; then
    touch ${LOCKFILE}
    success
  else
    failure
  fi
  echo
  return ${RETVAL}
}

Can anyone explain what the bold part of the function means?

It's either pseudocode or the commands success and failure are defined elsewhere.
# 3  
Old 03-07-2010
The entire script is:

Code:
#!/bin/bash

EMAIL="user@domain.com"
RESTARTSUBJECT="["`hostname`"] - System Startup"
SHUTDOWNSUBJECT="["`hostname`"] - System Shutdown"
RESTARTBODY="This is an automated message to notify you that "`hostname`" starte                                                                              d successfully.
Start up Date and Time: "`date`
SHUTDOWNBODY="This is an automated message to notify you that "`hostname`" is sh                                                                              utting down.
Shutdown Date and Time: "`date`
LOCKFILE=/var/lock/subsys/SystemEmail
RETVAL=0

# Source function library.
. /etc/init.d/functions

stop()
{
echo -n $"Sending Shutdown Email: "
echo "${SHUTDOWNBODY}" | mutt -s "${SHUTDOWNSUBJECT}" ${EMAIL}
RETVAL=$?

if [ ${RETVAL} -eq 0 ]; then
rm -f ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}

start()
{
echo -n $"Sending Startup Email: "
echo "${RESTARTBODY}" | mutt -s "${RESTARTSUBJECT}" ${EMAIL}
RETVAL=$?

if [ ${RETVAL} -eq 0 ]; then
touch ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}

case $1 in
stop)
stop
;;
start)
start
;;
*)
esac
exit ${RETVAL}

# 4  
Old 03-07-2010
The functions succes and failure are defined in the script:
Code:
/etc/init.d/functions

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Understanding an example of perl map() function

Hello, I have many folders under which there is always a file with the same name, which contains the data I need to process later. A perl oneliner was borrowed perl -e 'print "gene_id\t", join("\t", map {/(.*)\//; $1} @ARGV),"\n";' *_test.trim/level.csvto make a header so that each column... (5 Replies)
Discussion started by: yifangt
5 Replies

2. Shell Programming and Scripting

Problem with (Understanding) function

I have this code #!/bin/bash LZ () { RETVAL="\n$(date +%Y-%m-%d_%H-%M-%S) --- " return RETVAL } echo -e $LZ"Test" sleep 3 echo -e $LZ"Test" which I want to use to make logentrys on my NAS. I expect of this code that there would be output like 2017-03-07_11-00-00 --- Test (4 Replies)
Discussion started by: matrois
4 Replies

3. Shell Programming and Scripting

Need help understanding a function

Hello, I recently started going in depth with the shell, so I started learning from Linux Shell Scripting CookBook, 2nd edition. I am at the first chapter atm, and the author tells to define a function in the ~/.bashrc. The function is below. prepend() { && eval $1=\"$2':'\$$1\" && export... (1 Reply)
Discussion started by: Vaseer
1 Replies

4. Shell Programming and Scripting

Help Needed in understanding this command

Hi All, I search the forum for my query, Glad that got solution to it. But i really want to understand how does this command work. sed -e ':a' -e 's/\("*\),\(*"\)/\1~\2/;ta' Basically it is replacing all the comma(,) characters in between quotes with a tilde. Specially what does ':a' ,... (2 Replies)
Discussion started by: DSDexter
2 Replies

5. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

6. Shell Programming and Scripting

Oracle Function Needed

Dear Experts, Please find below the script in perl and can any body convert this script exactly in to oracle 9i fiunction which will return the required result same as perl. #!/usr/bin/perl $nof=@ARGV; @var2 = (); for($n=0; $n<$nof; $n++) { $filename = @ARGV; open... (3 Replies)
Discussion started by: shary
3 Replies

7. Shell Programming and Scripting

help needed at awk function

hi, I am new to scripting and need your help to debug . Here is my goal, I need to collect text,validate it and say if there is any error .below is the code validate_fn() { awk ' .... END { if(condition) return 0 ... (2 Replies)
Discussion started by: rider29
2 Replies

8. Shell Programming and Scripting

Needed help in understanding these procedures?

Hi all, i needed some help in understanding a few procedures and how exactly is the sequence? FINISHED="Done" COLUMNS=$( stty -a | head -n 2 | cut -d " " -f2 |cut -d " " -f4 ) COLS=$((${COLUMNS} -${#FINISHED} - 5)) RET_ARR="\010" KILLLINE=${RET_ARR}${RET_ARR} for i in $(seq 1... (0 Replies)
Discussion started by: wrapster
0 Replies

9. Shell Programming and Scripting

Help needed to Keep calling a function after every 5 seconds.

Hey guys.! Need some help.I want to write a script , which should be continuosly running and should keep calling a function after every say 5 or 10 seconds. I am done with almost all part of it, but figuring out how to keep the script continuosly running and how to keep calling a function after... (11 Replies)
Discussion started by: nua7
11 Replies

10. Shell Programming and Scripting

Help needed in function calling in a script

:confused:Hi , I have a script as shown below: rpttxt() { name="$*" awk '/'"${name}"'/ {print $2 $3"=" $4}' file.txt } xx = rpttxt "COL_HEAD_1" awk 'BEGIN {printf("%36s \n ","'"$xx"'")}' rpttxt() is a function..I want to store the final result of this function in... (3 Replies)
Discussion started by: jisha
3 Replies
Login or Register to Ask a Question