getting error tput: No value for $TERM and no -T specified when trying to connect from jenkins to jmeter servers - linux

i am using distributed framework for performance testing where i have 1 controller jmeter machine and 2 jmeter machines are working as load generators.I am trying to connect all the machines from jenkins server and executing shell script on controller machine to execute the test.Setup was working fine but from last couple of days i start getting following error
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
Below are the shell scripts, i am executing from jenkins server
#!/bin/bash
USERNAME=jmeter
HOSTS="jmeter01.com jmeter02.com"
#SCRIPT="source .bash_profile; alias ; pwd"
for HOSTNAME in ${HOSTS} ; do
echo "Connecting with host name : ${HOSTNAME}"
ssh -T -o StrictHostKeyChecking=no ${USERNAME}#${HOSTNAME} "${SCRIPT}"
echo "ssh connection successful with ${HOSTNAME} "
done

try 't' instead of 'T'
ssh -t -o StrictHostKeyChecking=no ${USERNAME}#${HOSTNAME} "${SCRIPT}"

Related

Why am I getting "setterm: $TERM is not defined" when I SSH into another server?

I'm SSH-ing from one remote server to another to run a couple of commands. My here-doc runs fine on the destination server but I'm getting this setterm: $TERM is not defined warning even though it is defined as linux on both servers. I tried export TERM=linux before the ssh command and in the Here-Doc.
Here-doc:
ssh -T $DestinationServer <<EOF
export TERM=linux
echo "Successfully SSH into \$HOSTNAME..."
echo \$TERM
*do some stuff*
EOF
Output:
setterm: $TERM is not defined.
Successfully SSH into HOSTNAME..."
linux
How do I fix this? And does this effect other commands in the Here-Doc?
UPDATE
I scrapped the Here-Doc and the setterm error went away. While it fixed my problem, why did the error resolve when I do it this way?
DoesThisExist=$(ssh -T $DestServer "cat $SomeFile" | grep -cim1 $This")

bash + how to avoid specific messages in the log file

when I run the bash script on my Linux machine we get the following errors in my log ,
note - we set in the script:
exec > $log 2>&1 , ( in order to send all standard error/output to $log )
the errors messages:
tput: No value for $TERM and no -T specified
in order to filter this errors messages we try to set in the bash script that:
export TERM=xterm
but without help
after digging we found that happened in some case for example when we perform ssh to remote machine and runs commands on remote machine VIA ssh
in order to avoid that we set TERM=xterm in the bash script as the following:
ssh user#$remote_machine "TERM=xterm /tmp/script.sh"
but it’s very not elegant solution and because my script use a lot of ssh and curl command then it’s not practical solution to set this on each SSH or curl etc
so my big question is
how to filter the message – tput: No value for $TERM and no -T specified ?
so we not get these ugly message in my $log file
Filter out all tput: No value from logging:
exec > >(grep -v 'tput: No value for $TERM and no -T specified' >$log) 2>&1

Need to ssh and run a single command as part of a larger bash script

My script is basically a convenient way to do remote shutdown and wakeonlan. The script runs from my Raspberry Pi
Shutting down my desktop is easy, but when I shut down my home server, I first would like to turn off my seedbox virtual machine (which is running on my home server) by connecting to it via SSH and issuing "shutdown -h now"
TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
echo "$TIMESTAMP: shutting down seedbox virtual machine" >> ${LOG_FILE}
sshpass -p " " ssh -o StrictHostKeyChecking=no lukesau#192.168.1.27
sleep 5
sudo shutdown -h now
sleep 60
TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
echo "$TIMESTAMP: shutting down $TARGET" >> ${LOG_FILE}
net rpc shutdown -f -t 5 -C 'Shutting down in 5 seconds' -U lukesau%pass -I 192.168.1.99
The seedbox is a Mac OS X virtual machine running in VMware. Perhaps there is a better way to shut down a VM before shutting down the host OS
That's not how it works, ssh isn't going to read the following commands from your input file. You can specify the command to be executed right after ssh
sshpass -p " " ssh -o StrictHostKeyChecking=no lukesau#192.168.1.27 \
'sh -c "sleep 5 ; sudo shutdown -h now ; sleep 60"'
This is assuming that you want these 3 commands executed via the ssh and the rest "locally" again.
I don't take guarantee for the quoting, nor for you sshpass construction as I have no manual for that.

SSH: Execute a command and keep the shell open [duplicate]

I find myself needing to log into various servers, set environment variables, and then work interactively.
e.g.
$ ssh anvil
jla#anvil$ export V=hello
jla#anvil$ export W=world
jla#anvil$ echo $V $W
hello world
How can I combine the first few commands, and then leave myself at a prompt?
Something like:
$ ssh anvil --on-login 'export V=hello; export W=world;'
jla#anvil$ echo $V $W
hello world
Obviously this is a model problem. What I am really asking is 'how do I ssh to a different machine, run some commands, and then continue as if I'd run them by hand?'
Probably the simplest thing is:
$ ssh -t host 'cmd1; cmd2; sh -i'
If you want to set variables, do:
$ ssh -t host 'cmd1; cmd2; FOO=hello sh -i'
Note that this is a terrible hack, and you would be much better off putting your desired initial commands in a script and doing:
$ scp setup host:~
$ ssh host
host$ . setup
You could also use the following expect script:
#!/usr/bin/expect -f
spawn ssh $argv
send "export V=hello\n"
send "export W=world\n"
send "echo \$V \$W\n"
interact
Turns out this is answered by this question:
How can I ssh directly to a particular directory?
to ssh:
ssh -t anvil "export V=hello; export W=world; bash"
followed by:
jla#anvil$ echo $V $W
hello world
It is worth to note that ssh -t can actually be used to connect to one host via another host.
So for example if you want to execute a command on anvil, but anvil is only accessible from host gateway (by firewall etc.), you can do like this:
ssh gateway -t 'ssh anvil -t "export V=hello; export W=world;bash -l";'
Exiting the anvil, will also log you out of gateway (if you want to stay on gatway after leaving anvil than just add another bash -l before closing the command.
Another approach is to execute this beast (also gives me a colored shell):
ssh host -t "echo 'rm /tmp/initfile; source ~/.bashrc; cd foo/; git status' > /tmp/initfile; bash --init-file /tmp/initfile"

ssh "port 22: no route to host" error in bash script

I wrote a scipt to execute a couple of ssh remote comands relating to apache storm. When I execute the script it says:
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: Connection refused
If I execute the commands manually it works out well and I can ping the machine. So that there has to be something wrong with this code:
while [ $i -le $numVM ]
do
if [ $i -eq 1 ];then
ssh -i file root#IP1 './zookeeper-3.4.6/bin/zkServer.sh start'
else
ssh -i file root#IP2 'sed -i '"'"'s/#\ storm.zookeeper.servers.*/storm.zookeeper.servers:/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
ssh -i file root#IP2 'sed -i '"'"'0,/^#[[:space:]]*-[[:space:]]*\"server1\".*/s//" - \"'${IParray[1]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
ssh -i file root#IP2 'sed -i '"'"'s/#\ nimbus.host:.*/"nimbus.host: \"'${IParray[2]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
ssh -i file root#IP2 './zookeeper-3.4.6/bin/zkCli.sh -server ${IParray[1]} &'
sleep 10
ssh -i file root#IP2 './apache-storm-0.9.3/bin/storm nimbus &' &
sleep 10
ssh -i file root#IP2 './apache-storm-0.9.3/bin/storm ui &' &
sleep 10
ssh -i file root#IP2 './apache-storm-0.9.3/bin/storm supervisor &' &
fi
((i++))
done
I'm starting several processes on 2 virtual machines that are deployed from the same image, so that they are identical in general. The confusing part is, that the first ssh command (zkServer.sh start) is working well but if I the script tries to execute the three "sed"-ssh-commands I get the error message above. But then the last four ssh-commands are working out well again. That does not make any sense to me...
Several things I can think of:
Most sshd daemons won't allow root access. Heck, many versions of Unix/Linux no longer allow root login. If you need root access, you need to use sudo.
The sshd daemon on the remote machine isn't running. Although rare, some sites may never had it setup, or purposefully shut it off as a security issue.
Your ssh commands themselves are incorrect.
Instead of executing the ssh commands in your shell script, modify the shell script just to print out what you're attempting to execute. Then, see if you can execute the command outside of the shell script. This way you can determine whether the problem is the shell script, or the problem is with the ssh command itself.
If your ssh commands don't work outside from the command line, you can then simplify them and see if you can determine what the issue could be. You have ssh -i file root#IP2. Is this suppose to be ssh -i $file root#$IP2? (i.e., you're missing the leading sigil).
$ ssh -i file root#$IP2 ls # Can't get simpler than this...
$ ssh -i file root#IPS # See if you can remotely log on...
$ ssh root#IP2 # Try it without an 'identity file'
$ ssh bob#IP2 # Try it as a user other than 'root'
$ telnet IP2 22 # Is port 22 even open on the remote machine?
If these don't work, then you have some very basic issue with the setup of your remote machine's sshd command.

Resources