title: grep in Shell Script
body: <p>I am trying to write a shell script that allows me to logon to a remote machine to see which users are running vtwm process for more than 14 days. Here is what I have written so far. </p>
  
  <p>There are two problems</p>
  
  <ol>
  <li><p>there might be more than one user with this active process. How do I save all of them in a variable?</p></li>
  <li><p>How do I figure out which one has been logged on for more than 14 days?</p></li>
  </ol>
  
  <p>The following code was written with the assumption that there is only one user with active vtwm process. But it does not work because grep command does not recognize the variable $u.
  so i can never get the date on which the user logged in. I cannot get mth1 and day1 to work because of problems with grep.</p>
  
  <pre><code>u=$(ssh host "w | grep vtwm | cut -d' ' -f1")
  echo "USER:"$u
  if [ -n "$u" ] then           
  mth1=$(who | grep -i $u | cut -d' ' -f10 | cut -d'-' -f2)
  mth2=$(date +"%m")
  day1=$(who | grep -i $u | cut -d' ' -f10 | cut -d"-" -f2)
  day2=$(date +"%d")
  if [ $mth1==$mth2 ] then
  #do something
  elif[ $mth1!=$mth2 ] then
  #do something
  fi
  fi
  </code></pre>