1

I have a bash script with following:

USERLIST="/tmp/adusers.list.names.only.txt"
cat $USERLIST | while read users
do
num=$[$num+1]
USR=`echo $users | awk '{print $1}'`
STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`
echo "$USR : $STATUS"
done

But command not getting user name, instead its showing $USR variable.

winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'

I tried to double quote like "$VAR" but no use.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Syed Jahanzaib
  • 145
  • 1
  • 1
  • 7
  • Possible duplicate of [Single quote within double quotes and the Bash reference manual](http://unix.stackexchange.com/questions/169508/single-quote-within-double-quotes-and-the-bash-reference-manual) – roaima Feb 13 '17 at 12:55

1 Answers1

2

It looks like the $USR part in the winexe call is not being translated into the variable because it's inside a single quote (')

Try changing the line

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`

into

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser '"$USR"' -Properties * | select Enabled"'`

so as to escape the single-quote, enter a double-quote and thereby insert the variable value.

anaotha
  • 846
  • 1
  • 7
  • 12
  • yes i tried to escape the single-quote/double quote by above method, but then the script does not proceed further and pause at following . (output) `root@linux:/temp# ./test.sh + USERLIST=/tmp/adusers.list.names.only.txt + read users + cat /tmp/adusers.list.names.only.txt + num=1 ++ awk '{print $1}' ++ echo $'user1.local\r' + USR=$'user1.local\r' -Properties * | select Enabled"'ADPASS //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser user1.local` afterword it does not move further – Syed Jahanzaib Feb 14 '17 at 03:31