Pls comment on my script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pls comment on my script.
# 1  
Old 11-19-2008
Pls comment on my script.

Hi guys, hope you scripting gurus here can help me out, the logic in my script somehow not working the way it should, this script part of a bigger backup script suppose to do some checking on the cluster prior to bringing up the package on MC/SG after backend cloning operation, this portion is suppose to check switching parameter if it is disabled, if so then turn it on with command "cmmodpkg -v -e -n hostname package_name", somehow it's not working. Smilie


Quote:
#!/bin/ksh
export PRISTAT=`/usr/sbin/cmviewcl -v | grep -i current | awk '{ print $3 }'`
export SECSTAT=`/usr/sbin/cmviewcl -v | grep -i alternate | awk '{ print $3 }'`
#
check_switching_mode()
{
# Check Primary node
if [ $PRISTAT!="enabled" ]
then
echo $PRISTAT
echo "cmmodpkg -v -e -n PRIMARY PACKAGE_NAME"
else
echo "switching mode on Primary is already enabled"
fi
# Check Secondary node
if [ $SECSTAT!="enabled" ]
then
echo $SECSTAT
echo "cmmodpkg -v -e -n SECONDARY PACKAGE_NAME"
else
echo "switching mode on Secondary is already enabled"
fi
}
check_switching_mode
when I run it the output is like this
# ./ccc
enabled <<<--- from echo $PRISTAT
cmmodpkg -v -e -n PRIMARY PACKAGE_NAME <<<--- this is wrong output
enabled <<<-- from echo $SECSTAT
cmmodpkg -v -e -n SECONDARY PACKAGE_NAME <<< -- this also wrong output

which is wrong.

the output from cmviewcl
# /usr/sbin/cmviewcl -v | grep -i current | awk '{ print $3 }'
enabled

# /usr/sbin/cmviewcl -v | grep -i alterna | awk '{ print $3 }'
enabled

can somebody pls help me.

Last edited by sparcguy; 11-19-2008 at 11:48 PM..
# 2  
Old 11-20-2008
Just to make sure, put double brackets around the if tests and write it like following:
Quote:
if [[ $PRISTAT != "enabled" ]]
Also you can have a " | od -c " following up to the echo on $PRISTAT to make sure there aren't any other characters in there.
# 3  
Old 11-20-2008
wow zaxx, solid man! makes a lot of difference

# ./ccc
switching mode on Primary is already enabled
switching mode on Secondary is already enabled


one thing tho just for me to understand,

what's the difference between the statement

[ $STAT2="running" ]


[[ $PRISTAT != "enabled" ]]

Both are working, my question is does the space around the = makes any difference?
# 4  
Old 11-21-2008
To be honest I don't know nor didn't try out. I always have a blank on each side of the testing operator/sign for better readability.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a file with comment in script

Hello, Be indulgent for my english. Can you help me ? function f1 { } egrep -v '^#' list_file \ | while read arg1 arg2 arg3 arg4; do f1 $arg1 $arg2 $arg3 $arg4 done In list_file there is I want to replace list_file by a $var then when i launch the script with a file's... (13 Replies)
Discussion started by: amazigh42
13 Replies

2. UNIX for Dummies Questions & Answers

Easiest way to comment/uncomment a shell script?

cd path line1 line2 line3 line4 line5 Lets say thats the sample script...So say if i have to comment the above script, which would be the better way so that whenever i want, i cud comment or uncomment the same. Thanks (1 Reply)
Discussion started by: saggiboy10
1 Replies

3. Shell Programming and Scripting

Comment/Devbug traverser ruby Script

Hello all, i need some help, having never herd of ruby before i joined my workplace im now saddled with alot of scripts written in ruby and i need to find out how to debug certain things (values of array's hashes etc). What i need is how to view each step in this command in a log file: ... (0 Replies)
Discussion started by: limamichelle
0 Replies

4. Shell Programming and Scripting

Need to comment some code via script

Hi, I am writing a shell script, which should comment a if-fi loop in a file. From google i found that, we can use below qualifier to comment a section of code, :<<COMMENT COMMENT But i could not place these keywords before and after if-fi loop. Any help would be appreciated. Finally the... (2 Replies)
Discussion started by: successlin
2 Replies

5. UNIX for Dummies Questions & Answers

multiline comment in shell script

Is thery any way to give comment to multiple line without explicitly specifying # at the begining of each line ? (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

6. UNIX for Dummies Questions & Answers

Why do a unix script starts with a comment?

For eg: #!/usr/bin/ksh <remaining code goes here> .. .. Does the compiler ignores that? Thanks (2 Replies)
Discussion started by: ajincoep
2 Replies

7. Shell Programming and Scripting

comment and uncomment a line with Shell Script

Requirement is: 1. comment and uncomment the line with Shell Script: /opt/admin/fastpg/bin/fastpg.exe -c -=NET (using fastpg.exe as a search option) 2. display = "Commented" (when its commented) and display = "Uncommented" (when its uncommented) Its urgent, please let me asap!!! Thanks in... (2 Replies)
Discussion started by: anthonyraj75
2 Replies

8. Shell Programming and Scripting

comment out a cron job as part of a script

Greetings, I am creating a ksh script to automate the installation of a utility on many servers. As part of this install, I want to check for a job in root's crontab. If the job exists, I need to comment it out. I know I will need to copy off the crontab then read it back in, but I am... (4 Replies)
Discussion started by: 22blaze
4 Replies

9. Shell Programming and Scripting

help needed for multiline comment deleting script

Hi I have a script to delete the multiline comments as below ******************************************** #!/usr/bin/sed -f #Replaces single line comment s://.*:: #Replaces multiline comment present in a single line s:/\**\*/::g #Starting of the loop for checking the starting of the... (1 Reply)
Discussion started by: aster007
1 Replies

10. Shell Programming and Scripting

Block Comment in Shell script

how to put multiline comments in a shell script like /* Some code */ in C language? (3 Replies)
Discussion started by: skyineyes
3 Replies
Login or Register to Ask a Question