<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with deleting utmp entries in script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027222#M97488</link>
    <description>I wasn't questioning the ethics of your task but rather the wisdom of ever depending upon the contents of utmp for anything. Again, it represents a "best guess" and this applies to all flavors of UNIX. In any event, you had a logical error and I thought I had left you with a big enough clue to fix it (although even if it was working I'll bet it wouldn't do what you want it to do).&lt;BR /&gt;&lt;BR /&gt;Note this line:&lt;BR /&gt;'s/"$username"//g' &lt;BR /&gt;when the shell hands off this line to sed&lt;BR /&gt;"$username" is literally just that: "$username" --- when you probably meant for $username to be "joe".&lt;BR /&gt;&lt;BR /&gt;The fix is to do away with the single quotes:&lt;BR /&gt;&lt;BR /&gt;username="Joe"&lt;BR /&gt;&lt;BR /&gt;sed "s/${username}//g" &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;&lt;BR /&gt;This will replace every occurence of "Joe" with a null string. What you probably intended was deleting the line when the username was found.&lt;BR /&gt;&lt;BR /&gt;sed "/${username}/d" &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;</description>
    <pubDate>Wed, 07 Feb 2007 14:45:47 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-02-07T14:45:47Z</dc:date>
    <item>
      <title>Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027219#M97485</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a script which deletes PIDs of a specified user, but it is not deleting the entries in the utmp file ... any ideas?&lt;BR /&gt;Here's the script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;PATH=/usr/local/bin:/usr/bin:/bin&lt;BR /&gt;&lt;BR /&gt;kill_sessions()&lt;BR /&gt;{&lt;BR /&gt;    ps -ef | grep "$username" | sort | awk '{ print $2 }' &amp;gt;&amp;gt; killfile&lt;BR /&gt;    for i in `cat killfile`&lt;BR /&gt;    do&lt;BR /&gt;      kill "$i"&lt;BR /&gt;    done&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;erase_entries()&lt;BR /&gt;{&lt;BR /&gt;  /usr/sbin/acct/fwtmp &amp;lt; /etc/utmp &amp;gt; /tmp/utmp.out&lt;BR /&gt;  ls -l /tmp/utmp.out&lt;BR /&gt;  cat /tmp/utmp.out |&lt;BR /&gt;        sed -e 's/"$username"//g' &amp;gt; /tmp/new_utmp.out&lt;BR /&gt;  /usr/sbin/acct/fwtmp -ic &amp;lt; /tmp/new_utmp.out &amp;gt; /etc/utmp&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;while (true) do&lt;BR /&gt;  echo ""&lt;BR /&gt;  echo ""&lt;BR /&gt;  echo "Do you wish to unhang a user session ( Please type Yes or No) ? \c"&lt;BR /&gt;  read choice&lt;BR /&gt;  case "$choice" in&lt;BR /&gt;    "Yes") echo "Okay"&lt;BR /&gt;            echo "Server? \c"&lt;BR /&gt;            read server&lt;BR /&gt;            echo "Username? \c"&lt;BR /&gt;            read username&lt;BR /&gt;            kill_sessions&lt;BR /&gt;            erase_entries&lt;BR /&gt;                ;;&lt;BR /&gt;    "No")  echo "Exiting program."&lt;BR /&gt;            PATH=$HOME&lt;BR /&gt;            exit 1&lt;BR /&gt;            ;;&lt;BR /&gt;       *)   echo "Please type Yes or No at the prompt"&lt;BR /&gt;        ;;&lt;BR /&gt;  esac&lt;BR /&gt;done&lt;BR /&gt;PATH=$HOME&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.</description>
      <pubDate>Wed, 07 Feb 2007 13:23:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027219#M97485</guid>
      <dc:creator>Douglas James Cameron</dc:creator>
      <dc:date>2007-02-07T13:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027220#M97486</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am intentionally not going to fix your problem (because that is really not doing you a favor) but I will point out your fundamental error:&lt;BR /&gt;&lt;BR /&gt; 's/"$username"//g' &lt;BR /&gt;&lt;BR /&gt;NOTE: You are expecting variable instantiation to take place inside single quotes --- and that ain't gonna happen.&lt;BR /&gt;&lt;BR /&gt;Now, a better question is why you are doing this? At best, who and utmp/wtmp represent a "best guess" of who is on the system. A far better and more trustworthy resource is the process table (ps -e).</description>
      <pubDate>Wed, 07 Feb 2007 13:30:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027220#M97486</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-02-07T13:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027221#M97487</link>
      <description>Clay - you replied:&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I am intentionally not going to fix your problem (because that is really not doing you a favor) but I will point out your fundamental error:&lt;BR /&gt;&lt;BR /&gt;'s/"$username"//g' &lt;BR /&gt;&lt;BR /&gt;NOTE: You are expecting variable instantiation to take place inside single quotes --- and that ain't gonna happen.&lt;BR /&gt;&lt;BR /&gt;Now, a better question is why you are doing this? At best, who and utmp/wtmp represent a "best guess" of who is on the system. A far better and more trustworthy resource is the process table (ps -e). &lt;BR /&gt; &lt;BR /&gt;  &lt;BR /&gt;Hey Clay,&lt;BR /&gt;The reason I am doing this is to 'unhang' user sessions.  I am also making another error, the uer with multiple sessions is to have all but the first removed from the process table and all but the first entry removed from utmp.  I can't go into more detail than that, but it is on the up and up.&lt;BR /&gt;Now, one approach I could take is to use awk and manipulate the killfile with the getline function to be able to skip the first process.  The only reason I used sed was to try and 'null' the username entries from the utmp file, in effect logging them out of the system.</description>
      <pubDate>Wed, 07 Feb 2007 13:40:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027221#M97487</guid>
      <dc:creator>Douglas James Cameron</dc:creator>
      <dc:date>2007-02-07T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027222#M97488</link>
      <description>I wasn't questioning the ethics of your task but rather the wisdom of ever depending upon the contents of utmp for anything. Again, it represents a "best guess" and this applies to all flavors of UNIX. In any event, you had a logical error and I thought I had left you with a big enough clue to fix it (although even if it was working I'll bet it wouldn't do what you want it to do).&lt;BR /&gt;&lt;BR /&gt;Note this line:&lt;BR /&gt;'s/"$username"//g' &lt;BR /&gt;when the shell hands off this line to sed&lt;BR /&gt;"$username" is literally just that: "$username" --- when you probably meant for $username to be "joe".&lt;BR /&gt;&lt;BR /&gt;The fix is to do away with the single quotes:&lt;BR /&gt;&lt;BR /&gt;username="Joe"&lt;BR /&gt;&lt;BR /&gt;sed "s/${username}//g" &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;&lt;BR /&gt;This will replace every occurence of "Joe" with a null string. What you probably intended was deleting the line when the username was found.&lt;BR /&gt;&lt;BR /&gt;sed "/${username}/d" &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Feb 2007 14:45:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027222#M97488</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-02-07T14:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027223#M97489</link>
      <description>This may not appear as a reply to you Clay, but I'll eventually get the hang of the forums here.&lt;BR /&gt;&lt;BR /&gt;Thanks Clay .. I was missing a few things on the sed statement there.&lt;BR /&gt;&lt;BR /&gt;You actually helped me quite a bit (even though I know you're right, it would have helped more if I figured it out myself, from your clue) .. anyway thanks.&lt;BR /&gt;&lt;BR /&gt;Now all I have to do is figure out how to preserve the first entry in the process table and the utmp (don't ask me why) file..&lt;BR /&gt;&lt;BR /&gt;You should've received some points on that .. let me know if they didn't get added on.</description>
      <pubDate>Wed, 07 Feb 2007 15:04:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027223#M97489</guid>
      <dc:creator>Douglas James Cameron</dc:creator>
      <dc:date>2007-02-07T15:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with deleting utmp entries in script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027224#M97490</link>
      <description>Thanks again Clay, for your advice on the script.</description>
      <pubDate>Wed, 07 Feb 2007 15:50:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problem-with-deleting-utmp-entries-in-script/m-p/5027224#M97490</guid>
      <dc:creator>Douglas James Cameron</dc:creator>
      <dc:date>2007-02-07T15:50:08Z</dc:date>
    </item>
  </channel>
</rss>

