Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script is printing the code lines as part of the output

Status
Not open for further replies.

Sreekanth1521

Programmer
May 21, 2020
2
IN
#!/bin/bash

haf()
{
sshpass -p "$1" ssh -tt -o StrictHostKeyChecking=no "$2"@"$3" <<'SSH_EOF'

echo "request msha actions status" | /opt/tel/vs/ns/current/bin/ns_cli > txt1
tr -s " " < txt1 > txt2
cut -d " " -f 2 txt2 > txt3
var1=$(<txt3)

if [ "$var1" = "MASTER" ]
then
var2=1
elif [ "$var1" = "SLAVE" ]
then
var2=2
else
var2=3
fi
echo $var2 > txt4
rm txt1 txt2 txt3
logout
SSH_EOF
sshpass -p "$1" scp "$2"@"$3":~/txt4 .
var2=$(<txt4)
sshpass -p "$1" ssh -tt -o StrictHostKeyChecking=no "$2"@"$3" <<'SSH_EOF'
rm txt4
logout
SSH_EOF
rm txt4
return $var2
}



haf "$1" "$2" "$3"
FL1=$?



+++++++++++++++++++OUTPUT+++++++++++++++++++++++++
[highlight #8AE234]admin@tel:~$
/vs/ns/current/bin/ns_cli > txt1 request msha actions status" | /opt/tel
admin@tel:~$ tr -s " " < txt1 > txt2
admin@tel:~$ cut -d " " -f 2 txt2 > txt3
admin@tel:~$ var1=$(<txt3)
admin@tel:~$
admin@tel:~$ if [ "$var1" = "MASTER" ]
> then
> var2=1
> elif [ "$var1" = "SLAVE" ]
> then
> var2=2
> else
> var2=3
> fi
admin@tel:~$ echo $var2 > txt4
admin@tel:~$ rm txt1 txt2 txt3
admin@tel:~$ logout
Connection to 192.168.66.39 closed.
admin@tel:~$ rm txt4
admin@tel:~$ logout
Connection to 192.168.66.39 closed.[/highlight]
FL1=1

I do not want the colored text to be seen as part of my output.
Colored text is the script code itself.

My correct output is
FL1=1,

I just want this to be seen as my output.

I am running this script in Ubuntu 14.04.1

Thanks in advance
 
Change the [tt]sshpass[/tt] line to...

Code:
sshpass -p "$1" ssh -tt -o StrictHostKeyChecking=no "$2"@"$3" <<SSH_EOF [b]> /dev/null[/b]

...or...

Code:
sshpass -p "$1" ssh -tt -o StrictHostKeyChecking=no "$2"@"$3" <<SSH_EOF [b]> /some/path/logfile.log[/b]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top