0

I have 3 commands that i need to run on a remote server.

The 2 commands are simple version checks and 3rd command is basically a short program that checks version of my database. This is how it goes

#!/bin/sh

ssh -t user@server << EOF

#AIP_version
domaininfo -d $GLOBAL_DOMAIN -history | head -n -3 | tail -1 > /home/abc/aip_version.txt

## Fetching AIP Online Details ##

variable1=$(
echo "set feed off
set pages 0
select * from system_parameters where name like '%VERS%';
exit
"  | sqlplus /@aipprealias01
)
echo "$variable1" > aipo_version.txt

#Fetching RPAS-AIP Details

domaininfo -d $GLOBAL_DOMAIN -version | sed -n '4,7p' > /home/abc/rpas-aip_version.txt

EOF

When I try to run this script, it gives me below errors :

Pseudo-terminal will not be allocated because stdin is not a terminal.

-bash: line 8: SQL*Plus:: command not found

-bash: line 10: syntax error near unexpected token `c'

-bash: line 10: `Copyright (c) 1982, 2014, Oracle. All rights reserved.'

I'd need help in understanding how can this error be resolved and secondly how can I run this script to do ssh on multiple servers rather than just 1 ? Thanks!

1
  • You can try copying the file to the remote system manually and then run it there (just ssh). Does it work? make sure you are using the right shell. Once that works locally at the remote system, you can move on and try to ssh -t it. Dec 29, 2021 at 14:49

2 Answers 2

1

Change the heredoc marker from EOF to a single-quoted string, 'EOF'. This will prevent the local shell evaluating $( ... ) commands and $variable variables.

For example, contrast this with the single quotes around the EOF marker (as shown) and then without:

nl << 'EOF'
Numbered line
And another $(date)
EOF

Output with single quotes

 1  Numbered line
 2  And another $(date)

Output without quotes

 1  Numbered line
 2  And another 29 Dec 2021 16:20:40
0

Your shell substitute the *, run the command locally... Try this:

    cat <your_script_body.txt>|ssh user@server "$(cat)"

your_script_body.txt :

#AIP_version
domaininfo -d $GLOBAL_DOMAIN -history | head -n -3 | tail -1 > /home/abc/aip_version.txt

## Fetching AIP Online Details ##

variable1=$(
echo "set feed off
set pages 0
select * from system_parameters where name like '%VERS%';
exit
"  | sqlplus /@aipprealias01
)
echo "$variable1" > aipo_version.txt

#Fetching RPAS-AIP Details

domaininfo -d $GLOBAL_DOMAIN -version | sed -n '4,7p' > /home/abc/rpas-aip_version.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.