#!/bin/bash
echo "Number of hosts entered are "$#
echo "Hostnames are "$@
for i in "$@"
do
echo "Logging in to the host "$i
pbsh root@$i '
ipaddr=`ip r | awk '{print $9}'`
if [ ipaddr = 172.*.*.* ]
then
echo "Script can not be run in this IP series"
exit
else
cd /var/tmp ; wget http://**********
fi'
done
After executing the above script it is throwing below error. The script is getting execute but not in the desired way.
awk: cmd. line:1: {print
awk: cmd. line:1: ^ unexpected newline or end of string
I am newbie to the scripting. Kindly correct me if anything wrong in the script.
In the listing which you posted, the opening single quote in the pbsh
line is closed by single quote immediately followed by the awk
command. You can escape the latter by prefixing it with a backslash.
If pbsh also accepts the command to be executed from stdin, an alternative would be to use a HERE document (see the bash man-page, section Here Documents ).
UPDATE: Gordon Davisson is right in his comment. \\'
doesn't work either. pbsh insists on getting the command to be executed as a single argument, you could either fiddle around with the quotes, as he suggested, or put the whole input for pbsh into a separate file and use, ie,
pbsh root@$i $(<input_script.pbsh)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.