1

I am trying to execute a command in Linux servers to fetch which all servers requires root password reset as there are multiple servers I am using an expect script to automate it , my command contains special characters like double quotes and grave accent ` . so on execution it give extra characters after double quotes as an error .

send " chage -l root | grep -i "Password expires" | if [[ `awk -F : '{print $2}' ` = "never" ]] ; then echo "password needs to be changed " ;else echo "skipping reset " ; fi;\r"

I tried using \ with double quotes but the error remains same

  • ` is not the problem, the problem is $2 in the awk script. – Johannes Kuhn Mar 12 '16 at 10:55
3

If you want a string with no interpolation in Tcl (the language expect uses), and it does not have have {} chars or variables you want to expand, then enclose it in {}. Eg:

send { chage -l root | grep -i "Password expires" | if [[ `awk -F : '{print $2}' ` = "never" ]] ; then echo "password needs to be changed " ;else echo "skipping reset " ; fi;}
send \r
0

Where did you put back-slashes? On all quotes or only on the inner ones like this?

send " chage -l root | grep -i \"Password expires\" | if [[ `awk -F : '{print \$2}' ` = \"never\" ]] ; then echo \"password needs to be changed \" ;else echo \"skipping reset \" ; fi;\r"

And yes, you need to \ a $ character also, because this string will be passed to the command and you don't need bash to resolve it too early.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.