ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am newbie to the forum and to scripting as well. Please help me out on this. I have written a script which checks to see if the server is down if it is down it has to exit the program, if not it should execute the scripts. Below is the sript and error I am seeing. where xyz.sh is the script I run, abc.sh and efg.sh should be excuted from with the xyz.sh script.Please help me with this. Thanks in advance:
#--------------------------------------------------------------
# checking if the server has started
#--------------------------------------------------------------
print "checking to see if server " + serverName + " is running on node " + nodeName
runningServer = AdminControl.completeObjectName("type=Server,node=" + nodeName + ",process=" + serverName + ",*")
# Following if block execute when server is down
# else block executes when server is up and running.
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
# return
else
'bash -c /home/abc.sh'
'bash -c /home/efg.sh'
return
Error:
Exception received while running file "/home/xyz.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
(no code object) at line 0
File "<string>", line 52
else
^
SyntaxError: invalid syntax
Like I said, use [CODE][/CODE] tags around your code in your post, so we can see the formatting better. For any language other than python, this is rather useful. As whitespace is a crucial part of python syntax, we cannot help you unless you put [CODE][/CODE] tags around your code. For example:
[CODE]your code in here[/CODE] produces
Code:
your code in here
If you're writing in python, then you need:
Code:
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
else:
'bash -c /home/abc.sh'
'bash -c /home/efg.sh'
return
or something similar - I'm not sure exactly what logic you need to code to follow.
Like I said, use [CODE][/CODE] tags around your code in your post, so we can see the formatting better. For any language other than python, this is rather useful. As whitespace is a crucial part of python syntax, we cannot help you unless you put [CODE][/CODE] tags around your code. For example:
[CODE]your code in here[/CODE] produces
Code:
your code in here
If you're writing in python, then you need:
Code:
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
else:
'bash -c /home/abc.sh'
'bash -c /home/efg.sh'
return
or something similar - I'm not sure exactly what logic you need to code to follow.
here it is:
Code:
#--------------------------------------------------------------
# checking if the server has started
#--------------------------------------------------------------
print "checking to see if server " + serverName + " is running on node " + nodeName
runningServer = AdminControl.completeObjectName("type=Server,node=" + nodeName + ",process=" + serverName + ",*")
# Following if block execute to check if the server is down
# else block executes when server is up and running.
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
else:
'bash -c /home/abc.sh'
'bash -c /home/efg.sh'
return
Right, in Python you need to line your code up correctly:
Code:
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
else: #this 'else' needs to line up with the 'if' line
#(i.e. the same number of spaces at the start of both)
'bash -c /home/abc.sh'
'bash -c /home/efg.sh' #this line needs to line up with the line before
return
Ideally, you would also make the 'print' and 'bash' lines line up, but if you don't it won't stop your code from running.
Thanks for responding the script seems not to throw any error but somehow its skipping this part of the code... I am working on it
Quote:
Originally Posted by Snark1994
Right, in Python you need to line your code up correctly:
Code:
if (len(runningServer) == 0):
print "Error -- Server " + serverName + " not running on node " + nodeName
else: #this 'else' needs to line up with the 'if' line
#(i.e. the same number of spaces at the start of both)
'bash -c /home/abc.sh'
'bash -c /home/efg.sh' #this line needs to line up with the line before
return
Ideally, you would also make the 'print' and 'bash' lines line up, but if you don't it won't stop your code from running.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.