Results 1 to 3 of 3
Hello,
I have several Oracle Database servers, I want to automate checkup on database by running one tput script that outputs me sql script+local disks info+some other stuff.
I'm kinda ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-02-2012 #1Just Joined!
- Join Date
- May 2012
- Posts
- 2
Need help with tput & ssh script
Hello,
I have several Oracle Database servers, I want to automate checkup on database by running one tput script that outputs me sql script+local disks info+some other stuff.
I'm kinda new to linux shell scripting, so I need yours help ppl
this is sample colors script that I found and tried to adapt.
Original:
Mine:Code:#!/bin/bash trap 'get_window_size' WINCH # trap when a user has resized the window _UNDERLINE_ON=`tput smul` # turn on underline _UNDERLINE_OFF=`tput rmul` # turn off underline get_window_size() { _WINDOW_X=`tput lines` _WINDOW_Y=`tput cols` _FULL_SPACES=`echo ""|awk ' { _SPACES = '${_WINDOW_Y}' while (_SPACES-- > 0) printf (" ") }'` _FULL_UNDERLINE=`echo "${_UNDERLINE_ON}${_FULL_SPACES}${_UNDERLINE_OFF}"` unset _FULL_SPACES show_menu return 0 } set_color() { tput clear PS3="Enter Selection[1-9]:" select _COLOR in "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" "Exit" do case ${REPLY} in [1-8]) _X=`expr ${REPLY} - 1`;; 9) break;; *) echo "Invalid Color"; continue;; esac if [[ ${1} = "b" ]] then tput setb ${_X} else tput setf ${_X} fi done } show_menu() { while [[ -z ${_ANS} ]] do tput civis tput clear cat <<- EOF Window Size: ${_WINDOW_X} / ${_WINDOW_Y} Select => ${_UNDERLINE_ON} ${_UNDERLINE_OFF} ${_FULL_UNDERLINE} B) Background Text Color F) Foreground Text Color X) Exit EOF tput rc tput smul tput cnorm read _ANS tput rmul case ${_ANS} in [Bb]) set_color "b";; [Ff]) set_color "f";; [Xx]) tput clear; exit;; *) echo -e "Invalid Selection: ${_ANS}\c" sleep 2 ;; esac unset _ANS done } tput sgr0 tput civis tput clear tput cup 3 10 tput sc tput cup 0 0 [[ -n ${_ANS} ]] && unset _ANS get_window_size exit 0
I get errors on ssh commandCode:#!/bin/bash # ~/.ssh/config trap 'get_window_size' WINCH # trap when a user has resized the window _UNDERLINE_ON=`tput smul` # turn on underline _UNDERLINE_OFF=`tput rmul` # turn off underline get_window_size() { _WINDOW_X=`tput lines` _WINDOW_Y=`tput cols` _FULL_SPACES=`echo ""|awk ' { _SPACES = '${_WINDOW_Y}' while (_SPACES-- > 0) printf (" ") }'` _FULL_UNDERLINE=`echo "${_UNDERLINE_ON}${_FULL_SPACES}${_UNDERLINE_OFF}"` unset _FULL_SPACES show_menu return 0 } set_server() { tput clear PS3="Enter Selection[1-9]:" select _COLOR in "Test" "PDM_DB" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" "Exit" do case ${REPLY} in [1-8]) _X=`expr ${REPLY} - 1`;; 9) break;; *) echo "Invalid Server Selection"; continue;; esac if [[ ${1} = "q" ]] then tput setb ${_X} elif [[ ${1} = "1"]] ssh .... /oracle/ORABACKUP/hpcc.sh;; else continue;; fi done } show_menu() { while [[ -z ${_ANS} ]] do tput civis tput clear cat <<- EOF Window Size: ${_WINDOW_X} / ${_WINDOW_Y} Select => ${_UNDERLINE_ON} ${_UNDERLINE_OFF} ${_FULL_UNDERLINE} Q) Israel Servers W) UK Servers X) Exit EOF tput rc tput smul tput cnorm read _ANS tput rmul case ${_ANS} in [Qq]) set_server "Israel Servers";; [Ww]) set_server "UK Servers";; [Xx]) tput clear; exit;; *) echo -e "Invalid Selection: ${_ANS}\c" sleep 2 ;; esac unset _ANS done } tput sgr0 tput civis tput clear tput cup 3 10 tput sc tput cup 0 0 [[ -n ${_ANS} ]] && unset _ANS get_window_size exit 0
./test2.sh: line 39: syntax error in conditional expression
./test2.sh: line 40: syntax error near `ssh'
./test2.sh: line 40: ` ssh .... /oracle/ORABACKUP/hpcc.sh;;'
what am I doing wrong?
p.s. tried with spawn ssh .... - same errors,
- 05-04-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,672
I don't understand what all the tput stuff is for...what is the goal of your script? it kind of sounds like you want to ssh to a bunch of oracle servers and run a shell script, is that right? If so, what about something like:
That script will ssh to two oracle servers (that you supply in place of ORACLE_SVR...) and execute the script specified. It will also indicate if the command completed successfully or not.Code:#!/bin/bash for server in <ORACLE_SVR1_IPADDR> <ORACLE_SVR2_IPADDR>; do echo -e "\nRunning remote command on Oracle server $server ... " ssh $server sh /path/to/hpcc.sh [ $? -eq 0 ] && echo OK || FAILED done
If you want it to be automated (e.g., so that you can run it from a cronjob and not be prompted for passwords), you'll want to set up ssh keys. This is very easy.
Code:# first generate the keys on the localhost for root, if they don't exist ssh-keygen -t dsa -f ~/.ssh/id_dsa -P '' # now copy them to your oracle servers ssh-copy-id -i ~/.ssh/id_dsa root@ORACLE_SVR1_IPADDR ssh-copy-id -i ~/.ssh/id_dsa root@ORACLE_SVR1_IPADDR
- 05-07-2012 #3Just Joined!
- Join Date
- May 2012
- Posts
- 2
THANKS!!! works like a charm!!!


Reply With Quote
