LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2016, 08:38 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Rep: Reputation: 0
Unhappy issue with function or call to function


Hey Guys,

Here is my script and its output. Having issue with it. Any guidance would be much appreciated !

Code:
set -x
export Blackout_Group=$1
export Duration=$2
export Change_INC_Number=$3

export conversion_value=60
export calc_in_minutes=$(echo "${Duration}"*"${conversion_value}"|bc|python -c "print int(round(float(raw_input())))")
echo ${calc_in_minutes}

LOG_FILE=${LOGS_DIR}/$(date +"%d-%^b-%Y-%H%M%S")_${Blackout_Group}_${calc_in_minutes}mins.log


case ${Blackout_Group} in
CCA)
        set OEM_Blackout_Group="CCB Asset Blackout"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_Number})
        ;;
CCR)
        set OEM_Blackout_group="CCB Retail Blackout"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_number})
        ;;
FUSION)
        set OEM_Blackout_Group="FUSION"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_number})
        ;;
Reporting)
        set OEM_Blackout_Group="Reporting Blackout"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_number})
        ;;
PM)
        set OEM_Blackout_Group="SOA Service Manager Blackout"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_number})
        ;;
ALL)
        set OEM_Blackout_Group="Blackout Entire PRD02 except DBs"
        create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_number})
        ;;
esac

exit 0

create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_Number})
{

emcli create_blackout -add_targets="${OEM_Blackout_Group}" -name="${Change_INC_Number}" -reason="Apps: Application Patch/Maintenance" -schedule="frequency:once;duration::"${calc_in_minutes};tzinfo:specified;tzregion:Australia/Victoria" -jobs_allowed

}
sh-4.1$
Output:
Code:
sh-4.1$ !.
./test2.sh CCA 0.1 12345
++ export Blackout_Group=CCA
++ Blackout_Group=CCA
++ export Duration=0.1
++ Duration=0.1
++ export Change_INC_Number=12345
++ Change_INC_Number=12345
++ export conversion_value=60
++ conversion_value=60
+++ echo '0.1*60'
+++ bc
+++ python -c 'print int(round(float(raw_input())))'
++ export calc_in_minutes=6
++ calc_in_minutes=6
++ echo 6
6
+++ date '+%d-%^b-%Y-%H%M%S'
++ LOG_FILE=/25-MAY-2016-111043_CCA_6mins.log
./test2.sh: line 16: syntax error near unexpected token `${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_Number}'
./test2.sh: line 16: `  create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_Number})'
sh-4.1
Any idea what is going wrong here ?

Jim
 
Old 05-24-2016, 09:28 PM   #2
dunne
Member
 
Registered: May 2014
Distribution: OpenBSD
Posts: 67

Rep: Reputation: 36

Is this supposed to be a shell function?
Code:
create_blackout(${OEM_Blackout_Group},${calc_in_minutes},${Change_INC_Number})
{

emcli create_blackout -add_targets="${OEM_Blackout_Group}"
-name="${Change_INC_Number}" -
reason="Apps: Application Patch/Maintenance"
-schedule="frequency:once;duration::"${calc_
in_minutes};tzinfo:specified;tzregion:Australia/Victoria" -jobs_allowed

}
I ask because that's not the right syntax. So, unless I am missing something:
1) Put the definition before it is called, and write it like so:
Code:
create_blackout()
{
...
}
2) You call it like so:
Code:
create_blackout $OEM_Blackout_Group $calc_in_minutes $Change_INC_Number
3) And in the function, you refer to the arguments using positional parameters:
first arg passed in is $1, second is $2, and so on.
 
Old 05-24-2016, 09:33 PM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
Yes it is a shell function. How can I call it and how to pass arguments while calling? As I would need the variables when i call and pass three parameters
can you guide me for that?
 
Old 05-24-2016, 09:47 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
It seems to be missing the first line to declare which script interpreter it needs. It could be this?

Code:
#!/bin/sh
  • The the ^b probably should be b
  • Functions have to be declared before use
  • Function parameters get passed just like with a regular program, as arguments and not inside parenthesis.
  • There is an unclosed double quote somewhere.
  • The case statement ought to have a catch-all default in case the wrong or no parameters are passed.
 
Old 06-02-2016, 01:04 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
Thank you very much all of you !! Issue is resolved.
 
Old 06-02-2016, 09:25 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please remember to mark question as SOLVED.

I would add that there is entirely to little quoting used around variables and not sure why you needed both bc and python to perform a calculation, surely only one is needed.
I was also curious which shell you are using as the use of 'set' for a variable is not a bashism and also why the use of export?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] read function call returning more amount of data than wiritten using write function chakka.lokesh Programming 1 09-11-2014 03:14 AM
[SOLVED] g++ error message no matching function for call to some function Jerry Mcguire Programming 6 04-13-2010 08:37 PM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
Compilation issue when Function is parameter in function call on LINUX sa20358 Linux - Software 2 07-24-2008 10:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration