I am creating a script that will ssh to a host and print all the user accounts and when they will expire.

On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all user accounts.

I have added this to a script that should go to a server, create this list and use it to print when it will expie.


for i in `cat /admin/lists/testlist`
  echo $i
  UNAME=`su - admin -c "ssh $i uname"`

  if test "$UNAME" = "Linux"
    LIST=`su - admin -c "ssh $i awk -F':' '{ print $1}' /etc/passwd"`
    for j in $LIST
      echo "$j " ; `su - batch -c "ssh $i sudo chage -l $j | grep Account"`

    echo "Exiting. The OS type is not found."

  echo "========================================================================"
  echo " "

exit 0

The issue I am having is when I run the script I get the following error.

[admin@testserver bin]$ sudo checkPasswdExpiration.sh
awk: cmd. line:1: {
awk: cmd. line:1:  ^ unexpected newline or end of string

Why does the awk command not work in this script?


The first set of quotes is eaten up by the command line for su, and the second set by the command line for ssh, so that the quoted { print $1} is actually seen as three separate arguments by awk. Escape the quotes (and $, and any other special character you may use):

su - admin -c "ssh $i awk -F: \'{ print \$1}\' /etc/passwd"


su - admin -c "ssh $i getent passwd" | awk -F: '{print $1}'

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.