<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>users Archives - Tom Barbette</title>
	<atom:link href="https://perso.uclouvain.be/tom.barbette/tag/users/feed/" rel="self" type="application/rss+xml" />
	<link>https://perso.uclouvain.be/tom.barbette/tag/users/</link>
	<description></description>
	<lastBuildDate>Thu, 05 Feb 2015 13:52:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://perso.uclouvain.be/tom.barbette/wp-content/uploads/2022/04/cropped-logo-uclouvain-2021-barbette-32x32.png</url>
	<title>users Archives - Tom Barbette</title>
	<link>https://perso.uclouvain.be/tom.barbette/tag/users/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Detecting if another user is connected on UNIX systems</title>
		<link>https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/</link>
		
		<dc:creator><![CDATA[Tom Barbette]]></dc:creator>
		<pubDate>Tue, 14 Jan 2014 10:11:06 +0000</pubDate>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[connected]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[users]]></category>
		<guid isPermaLink="false">http://queen.run.montefiore.ulg.ac.be/~barbette/?p=76</guid>

					<description><![CDATA[<p>How to detect if another user is connected to your machine or your server? You can use the command &#8220;users&#8221; to check yourself is someone is connected. But to do it automatically, you&#8217;ll have to use some pipe : [code lang=&#8221;bash&#8221;]expr length &#8220;`users &#124; sed -e &#8220;s/\($USER\&#124;\[ \]*\)//ig&#8221;`&#8221;[/code] The first thing executed by the shell &#8230; </p>
<p class="link-more"><a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/" class="more-link">Continue reading<span class="screen-reader-text"> "Detecting if another user is connected on UNIX systems"</span></a></p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/">Detecting if another user is connected on UNIX systems</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>How to detect if another user is connected to your machine or your server? You can use the command &#8220;users&#8221; to check yourself is someone is connected. But to do it automatically, you&#8217;ll have to use some pipe :</p>
<p>[code lang=&#8221;bash&#8221;]expr length &#8220;`users | sed -e &#8220;s/\($USER\|\[ \]*\)//ig&#8221;`&#8221;[/code]</p>
<p>The first thing executed by the shell will be the thing under french apostrophe ( ` ). Theses are for evaluation a command, and replace it by what it outputs (normally print on the screen). The command users print the list of connected users into a pipe, to sed which evaluate its command as a regular expression (-e parameter). The command is &#8220;s&#8221; for substitute, and the rest tells him to find &#8220;$USER&#8221; (replaced by the currently connected user, you) and spaces and replace them by &#8230; nothing. So this part will be an empty string if there is no other users connected than &#8220;$USER&#8221; and something not empty if there is.</p>
<p>The &#8220;expr length&#8221; return the length of a string. So this commands print 0 if there is no other user connected, and &gt;0 if there is some !</p>
<p>In a shell script to do something if yes or no&#8230;<br />
[code lang=&#8221;bash&#8221;]#!/bin/sh<br />
usersstripped=`users | sed -e &#8220;s/\(<strong>tom</strong>\|\[ \]*\)//ig&#8221;`<br />
connected=`expr length &#8220;$usersstripped&#8221;`<br />
if [ &#8220;$connected&#8221; -eq &#8220;0&#8221; ] ; then<br />
echo &#8220;No other user is connected&#8221;<br />
else<br />
echo &#8220;Other user connected !&#8221;<br />
fi[/code]</p>
<p>It is essentially the same command but done in two times, as in a shell script this command would not be evaluated correctly.</p>
<p>And if you want to put that in a cron to eg. send you a mail, you just have to type &#8220;crontab -e&#8221; and put a line like :</p>
<p>[code]* * * * * /home/tom/connected[/code]</p>
<p>To launch it every minutes. But if you do that you&#8217;d better do something like detecting a connection&#8230;</p>
<p>The post <a href="https://perso.uclouvain.be/tom.barbette/detecting-if-another-user-is-connected/">Detecting if another user is connected on UNIX systems</a> appeared first on <a href="https://perso.uclouvain.be/tom.barbette">Tom Barbette</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
