Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
` is not the problem, the problem is $2 in the awk script. – Johannes Kuhn Mar 12 at 10:55

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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