Within a Qt5 application I have a bash script which runs to check version numbers from certain files on other remote machines (that I ssh into).
I have over 100 machines that I can run this script on. If the machine I have sshed into has the file I am looking for the script output is nicely displayed, but if the file on the remote machine does not exist then my 2 lines join together.
e.g
Should look like this:
Operating System: 1.5.64
sw_install: 1.16
Kate 1.1
but if remote files don't exist I get
Operating System: sw_install
Kate: 1.1
Any ideas to get the lines to be separate if the remote files don't exist (if does happen). I don't just want to put an 'echo' line in between the 2 ssh commands (or remove the -n) as the output is not the desired look when the files do exist.
Hoping there is a really simple answer out there please.
Thank you very much for your help!!
echo -n "Operating System: "
ssh -t -o LogLevel=QUIET -o '''StrictHostKeyChecking no''' $NODENAME "cat /home/user/Version.txt"
echo -n "sw_intall: "
ssh -t -o LogLevel=QUIET -o '''StrictHostKeyChecking no''' $NODENAME "grep VERSION= /home/user/sw_install | cut -d'=' -f2 | tr -d '\"' | head -1"
ssh -t -o LogLevel=QUIET -o '''StrictHostKeyChecking no''' $NODENAME "rpm -qv kate --qf \" Kate: %{VERSION}.%{RELEASE}\""
Centos 7.2
-n
and put the ssh command into a command substitution likeecho "Operating System: $(ssh -t …)"
. I'm just wondering why don't get an error message if the file is missing. – Freddy Aug 05 '19 at 03:59grep -s
and catching the empty string like this:VERSION=$(grep -s VERSION= /home/user/sw_install | cut -d'=' -f2 | tr -d '\"' | head -1);echo ${VERSION:="no-text returned"}
– Philippos Aug 05 '19 at 07:13sw_install
file, but all your piping andgrep
ing andcut
ting andtr
ing andhead
ing can probably be replaced by a simplesed '/.*VERSION=/!d;s///;s/[\"]//g;q'
– Philippos Aug 05 '19 at 07:19