Interacitve script for Healthcheckup of nodes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interacitve script for Healthcheckup of nodes
# 8  
Old 05-09-2014
Just post what you attempt.
Place your code instead of the echo "string" commands.
# 9  
Old 05-10-2014
Code:
#!/bin/bash
echo "Enter the opt"
read opt
case $opt in
[1]) echo "SDP" ;;
break;
echo "Enter the IP:"
read IP
scp /tmp/test/SDP.sh sdpuser@$IP:/tmp/. ;
ssh sdpuser@$IP -t "sudo sh /tmp/SDP.sh > /tmp/sdp1.txt" ;
scp sdpuser@$IP:/tmp/sdp1.txt /tmp/. ;
ssh sdpuser@$IP 'rm /tmp/SDP.sh'
[2]) echo "AIR" ;;
[3]) echo "EMM" ;;
esac

I am unable to echo SDP and input IP at the same time.
is it not allowed in case statements?
Pls tel if any other option can be used
Moderator's Comments:
Mod Comment Please use CODE tags; not color changes when displaying sample input, output, and code segments.


---------- Post updated 05-10-14 at 05:04 AM ---------- Previous update was 05-09-14 at 01:46 PM ----------

Code:
ssh hostname@IP exec /tmp/SDP.sh > /tmp/sdp1.txt ;

What is wrong with this command?
It is showing no error but sdp1.txt is not getting created or even if it is created it is a blank file

Last edited by Don Cragun; 05-09-2014 at 04:02 PM.. Reason: Add CODE tags; remove COLOR tags.
# 10  
Old 05-10-2014
Given the situation you mention before, i'd go save that data (servername, url, local_script_location, remote_script_location,user, (password?)) either in a csv file or
as arrays directly inside the script.

So you then could let the user select among the "${servername[@]}" array, count out its index number, and read the other arrays index number into variables, so you can then re-use the actual 'work-code' one time for all the 'diffrent' servers.

Also, you could 'connect' the the ssh commands so you dont have to call it twice, thought that might be inconvienient.
Code:
ssh sdpuser@$IP -t  << EOF
sudo sh /tmp/SDP.sh > /tmp/sdp1.txt
rm /tmp/SDP.sh
EOF

However, would more imagine you want the txt-file removed, and leave the script there for reuse, so the above example would be un-usable?
Why you must run it as sudo (does that even work remote?) and invoke sh to execute an sh script which should be executeable anyway, is something i wonder about.
And this is what i would consider the cause for the either empty or non existing file...

Hope this helps and good night
# 11  
Old 05-12-2014
I must admit I'm a bit confused by this bit:-
Code:
case $opt in
[1]) echo "SDP" ;;
break;

I would drop the square brackets, unless you are planning to use an expression, but I think you have a structural error in the code. From what I understand, the actions taken when a case statement finds a match (in this case $opt is 1) is ended by a ;;, so I don't see how the rest of that block of code runs, indeed I would expect a syntax error of some sort, unless perhaps the error is missed because the break steps you out somehow.

I get this:-
Code:
# ./case_test
Enter the opt
1
./case_test: line 6: syntax error near unexpected token `;'
./case_test: line 6: `break;'
# ./case_test
Enter the opt
2
./case_test: line 6: syntax error near unexpected token `;'
./case_test: line 6: `break;'
#

May I suggest that you change it like this:-
Code:
#!/bin/bash
echo "Enter the opt"
read opt
case $opt in
   1) echo "SDP"                                                # Note that ;; is removed
                                                                # Note that break; is removed
echo "Enter the IP:"
read IP
echo scp /tmp/test/SDP.sh sdpuser@$IP:/tmp/.                    # ; removed
echo ssh sdpuser@$IP -t "sudo sh /tmp/SDP.sh > /tmp/sdp1.txt"   # ; removed
echo scp sdpuser@$IP:/tmp/sdp1.txt /tmp/.                       # ; removed
echo ssh sdpuser@$IP 'rm /tmp/SDP.sh'    ;;                     # End of case section here
[2]) echo "AIR" ;;
[3]) echo "EMM" ;;
esac

I now get the following output:-
Code:
# ./case_test  
Enter the opt
1
SDP
Enter the IP:
123.456.789.abc
scp /tmp/test/SDP.sh sdpuser@123.456.789.abc:/tmp/.
ssh sdpuser@123.456.789.abc -t sudo sh /tmp/SDP.sh > /tmp/sdp1.txt
scp sdpuser@123.456.789.abc:/tmp/sdp1.txt /tmp/.
ssh sdpuser@123.456.789.abc rm /tmp/SDP.sh
# ./case_test
Enter the opt
2
AIR
#

Obviously I didn't want to action the later commands, so they're just displays to show them. You will want some validity checking on the IP address too.. Mine is illegal in so many ways.


I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tabulate nodes and subnodes of XML file script

Hello to all, I'd like to tabulate the content of the XML file below, I've been trying with AWK putting the Top node (<KIND>) as RS and so far I'm able to print the first and second field of each record, but I don't know how to continue with the following nodes that have more inner nodes. The... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

2. UNIX for Dummies Questions & Answers

One service, two nodes, HA

Hi all. I have two nodes taken different places. They are connected together on a network. So, i have a service, it works on one of nodes and when the node is unavailable the service should will be launched on other node. Solution: rhel cluster, keepalive, hearbeat...may be Carp but what if... (2 Replies)
Discussion started by: Flomaster
2 Replies

3. High Performance Computing

request more nodes

I am new to cluster commands. But I have tried utilizing: -pe, but I do not know my parallel computing environment. We are running SGE, is there a simpler command to request more nodes? also: qsub -N auto -M name@email.com -m abe auto.sh does not email me at all. Help would be appreciated (0 Replies)
Discussion started by: theawknewbie
0 Replies

4. Shell Programming and Scripting

Run script on HACMP nodes?

Hello All, Anybody knows how can I run script on the AIX HACMP offline node, without logon a offline node? I would like to run a script on the online node and at same time or after the online node on the offline node. Any IDEA? :confused: (3 Replies)
Discussion started by: kalaso
3 Replies

5. Emergency UNIX and Linux Support

Rebooting 3 to 1 Cluster nodes.

hello Gurus, My current set up is 3 to 1 Cluster (SUN Cluster 3.2) running oracle database. Task is to reboot the servers. My query is about the procedure to do the same. My understanding is suspend the databases to avoid switchover. Then execute the command scshutdown to down the cluster... (4 Replies)
Discussion started by: EmbedUX
4 Replies

6. Shell Programming and Scripting

Script for showing only selected nodes

Dear all, I am bit confused lately, I have a xmlfile here: file: book.xml <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> ... (2 Replies)
Discussion started by: penyu
2 Replies

7. Shell Programming and Scripting

Shell script to map XML nodes

Hi folks, I'm a bit of a novice at this but here goes. I want to read in nodes from an XML file, and map the path to each. eg the file is structured <node><nodename>.</nodename> <node><nodename>topnode</nodename> <node><nodename>subnode1</nodename></node> ... (1 Reply)
Discussion started by: mark14
1 Replies

8. UNIX for Advanced & Expert Users

Managing nodes???

Does anyone know something about this? I have no idea what it means and how to do it. but if anyone can give me and explanation and also point me to a website, i'd really appreciate it (5 Replies)
Discussion started by: TRUEST
5 Replies

9. UNIX for Dummies Questions & Answers

nodes

how do you list all the nodes in unix :confused: (3 Replies)
Discussion started by: kamisi
3 Replies

10. UNIX for Dummies Questions & Answers

i-nodes

first off, i am new to unix so please bear with me. i was reading somewhere that if your i-nodes get critical that it can slow your network down. what are i-nodes and when do they become a critical number? this is what mine states: / (/dev/root ): 777058 blocks 569290 i-nodes... (4 Replies)
Discussion started by: djatwork
4 Replies
Login or Register to Ask a Question