how to ignore resolving $1 in awk as the positional parameter
i=$1
if [[ $# -eq 1 ]] then ssh -qt $i 'sudo dmidecode | grep -i Manufacturer | head -1 | awk -F"," '{print $1}'| awk -F":" '{print $2}' | tee -a test-raj' else echo "Usage: Please give server name as 1st argument" fi Here is the result of execution: dxxx-sa-unixmgmt@dxxxqxx01vsat01:~/raj # sh -x prepatch-script.sh CETQN1VTUTIxxx2 + i=CETQN1VTUTIxxx2 + [[ 1 -eq 1 ]] + ssh -qt CETQN1VTUTIxxx2 'sudo dmidecode | grep -i Manufacturer | head -1 | awk -F"," {print' 'CETQN1VTUTIxxx2}| awk -F":" {print' '} | tee -a test-raj' awk: cmd. line:1: {print awk: cmd. line:1: ^ unexpected newline or end of string awk: cmd. line:1: {print awk: cmd. line:1: ^ unexpected newline or end of string dxxx-sa-unixmgmt@dexxqxx01vsat01:~/raj # |
Quote:
Code:
ssh -qt $i 'sudo dmidecode | grep -i Manufacturer | head -1 | awk -F"," "{print $1}"| awk -F":" "{print $2}" | tee -a test-raj' |
Please use [code][/code] tags when displaying code/data.
I am not sure if veerain's suggestion will work? By using double quotes you open awk up to the shell parameters of $1 and $2, at least this is how it behaves inside a shell script. In a shell script you could escape the dollar signs and still use single quotes, or perhaps see if switching the quotes around helps: Code:
ssh -qt $i "sudo dmidecode | grep -i Manufacturer | head -1 | awk -F, '{print $1}'| awk -F: '{print $2}' | tee -a test-raj" |
Quote:
|
You have better luck by putting the command in a variable. That way all the quotes get evaluated on the assignment:
Code:
|
Quote:
Code:
$ foo='12\' |
Quote:
|
So here is some simplification of the command:
Code:
sudo dmidecode | awk -F: 'tolower($0) ~ /manufacturer/{print $2;exit}' | tee -a test-raj |
All times are GMT -5. The time now is 12:02 AM. |