<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:series="http://unfoldingneurons.com/"
		>
<channel>
	<title>Comments on: How to: Check the bash shell script is being run by root or not</title>
	<atom:link href="http://www.cyberciti.biz/tips/shell-root-user-check-script.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html</link>
	<description>This is a Linux sys admin journal by Vivek about sys admin work, Linux tips &#38; tricks, hacks, news and more.</description>
	<lastBuildDate>Sat, 20 Mar 2010 00:34:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-154365</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 18 Mar 2010 23:00:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-154365</guid>
		<description>Big help, thank you!</description>
		<content:encoded><![CDATA[<p>Big help, thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pierreact</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-154290</link>
		<dc:creator>pierreact</dc:creator>
		<pubDate>Mon, 15 Mar 2010 08:31:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-154290</guid>
		<description>An yet another bashism...</description>
		<content:encoded><![CDATA[<p>An yet another bashism&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lorenzo</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-153862</link>
		<dc:creator>lorenzo</dc:creator>
		<pubDate>Tue, 23 Feb 2010 11:58:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-153862</guid>
		<description>@hemanth

&#039;root&#039; username is not assured. It could be different. id=0 is what is used inside the kernel to identify the superuser (aka root)</description>
		<content:encoded><![CDATA[<p>@hemanth</p>
<p>&#8216;root&#8217; username is not assured. It could be different. id=0 is what is used inside the kernel to identify the superuser (aka root)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hemanth</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-152270</link>
		<dc:creator>hemanth</dc:creator>
		<pubDate>Mon, 14 Dec 2009 05:22:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-152270</guid>
		<description>I was using this : [[ `id -un` != root ]] &amp;&amp; echo You must be root &#124;&#124; mount /dev/sdb1 /mnt/disk2</description>
		<content:encoded><![CDATA[<p>I was using this : [[ `id -un` != root ]] &amp;&amp; echo You must be root || mount /dev/sdb1 /mnt/disk2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gurmad</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-151887</link>
		<dc:creator>gurmad</dc:creator>
		<pubDate>Fri, 27 Nov 2009 01:29:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-151887</guid>
		<description>Guys, please help..am a beginner to shell script and lecture gave this assingment:

1 Write a Shell script to automatically check that a specified user is logged in to the
computer.
The program should allow the person running the script to specify the name of the
user to be checked, the frequency in seconds at which the script should check. If a
checking frequency is not specified, it should default to 60 seconds
The script should check for the specified user and if found should output a message
with a “beep” or “bell” sound to the screen stating that the user is logged in. It should
also output a message to a log file stating that the user is logged in and specifying the
date and time.
If the user is not logged in the script should output a message without any “beep”
sound to the screen stating that the user is not logged in.
The script should allow a person running the script to specify the user name on the
command line and optionally, a check frequency in seconds and a third argument “q”
“q” . If “q” is present as a third argument, The script should omit any output to the
screen or “beep” sound but should log to a log file the message stating that the user is
logged in and giving the time.
The command to run the script would be as follows:
checklogin username 30 q where “checklogin” is the script name, “username” is the
name of the user, “30” is the optional frequency to check in seconds, and “q” is the
optional argument to suppress screen output.
The script should check that the number of arguments supplied is between 1 and 3 and
if it is not, should terminate with an error message showing the correct syntax for the
command.
.</description>
		<content:encoded><![CDATA[<p>Guys, please help..am a beginner to shell script and lecture gave this assingment:</p>
<p>1 Write a Shell script to automatically check that a specified user is logged in to the<br />
computer.<br />
The program should allow the person running the script to specify the name of the<br />
user to be checked, the frequency in seconds at which the script should check. If a<br />
checking frequency is not specified, it should default to 60 seconds<br />
The script should check for the specified user and if found should output a message<br />
with a “beep” or “bell” sound to the screen stating that the user is logged in. It should<br />
also output a message to a log file stating that the user is logged in and specifying the<br />
date and time.<br />
If the user is not logged in the script should output a message without any “beep”<br />
sound to the screen stating that the user is not logged in.<br />
The script should allow a person running the script to specify the user name on the<br />
command line and optionally, a check frequency in seconds and a third argument “q”<br />
“q” . If “q” is present as a third argument, The script should omit any output to the<br />
screen or “beep” sound but should log to a log file the message stating that the user is<br />
logged in and giving the time.<br />
The command to run the script would be as follows:<br />
checklogin username 30 q where “checklogin” is the script name, “username” is the<br />
name of the user, “30” is the optional frequency to check in seconds, and “q” is the<br />
optional argument to suppress screen output.<br />
The script should check that the number of arguments supplied is between 1 and 3 and<br />
if it is not, should terminate with an error message showing the correct syntax for the<br />
command.<br />
.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurie</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-148131</link>
		<dc:creator>Laurie</dc:creator>
		<pubDate>Wed, 15 Apr 2009 15:14:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-148131</guid>
		<description>@Diana

You need to put your code into the global .bashrc file, /etc/bashrc. This will become the default .bashrc. Beware though, if you make a user specific bashrc then you need to import the global bashrc</description>
		<content:encoded><![CDATA[<p>@Diana</p>
<p>You need to put your code into the global .bashrc file, /etc/bashrc. This will become the default .bashrc. Beware though, if you make a user specific bashrc then you need to import the global bashrc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arky</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-147598</link>
		<dc:creator>Arky</dc:creator>
		<pubDate>Mon, 09 Mar 2009 07:14:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-147598</guid>
		<description>@ terry 

The script works as expected.</description>
		<content:encoded><![CDATA[<p>@ terry </p>
<p>The script works as expected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Terry</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-144628</link>
		<dc:creator>Terry</dc:creator>
		<pubDate>Mon, 11 Aug 2008 21:55:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-144628</guid>
		<description>I think it&#039;s worth mentioning that $UID &amp; $EUID will not return the desired result if you use sudo to run  the script, id -u does however.</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s worth mentioning that $UID &amp; $EUID will not return the desired result if you use sudo to run  the script, id -u does however.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabio</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-142377</link>
		<dc:creator>Fabio</dc:creator>
		<pubDate>Sun, 06 Jan 2008 14:07:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-142377</guid>
		<description>Hi,
if you want to redirect a message to stderr using echo you have to use &quot;1&gt;&amp;2&quot; instead of &quot;2&gt;&amp;1&quot;.
For example,

~ &gt;&gt;  f(){
&gt; echo &quot;to stdout&quot; 2&gt;&amp;1
&gt; echo &quot;to stderr&quot; 1&gt;&amp;2
&gt; }
~ &gt;&gt;  f 2&gt;/dev/null
to stdout #this is printed to stdout
~ &gt;&gt;

bye</description>
		<content:encoded><![CDATA[<p>Hi,<br />
if you want to redirect a message to stderr using echo you have to use &#8220;1&gt;&amp;2&#8243; instead of &#8220;2&gt;&amp;1&#8243;.<br />
For example,</p>
<p>~ &gt;&gt;  f(){<br />
&gt; echo &#8220;to stdout&#8221; 2&gt;&amp;1<br />
&gt; echo &#8220;to stderr&#8221; 1&gt;&amp;2<br />
&gt; }<br />
~ &gt;&gt;  f 2&gt;/dev/null<br />
to stdout #this is printed to stdout<br />
~ &gt;&gt;</p>
<p>bye</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: diana</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141871</link>
		<dc:creator>diana</dc:creator>
		<pubDate>Fri, 16 Nov 2007 10:26:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141871</guid>
		<description>may be it was the wrong place to post this.Please help me,
  I would like to send mail for each success login.i tried with this,
and place this in /root/.bashrc
#!/bin/bash
echo `last $i &#124; head -1 &#124; awk &#039;{print $1&quot; &quot;$3&quot; &quot;$4&quot; &quot;$5&quot; &quot;$6&quot; &quot;$7}&#039;`&#124;while read output;
do
echo $output
ip=$(echo $output &#124; awk &#039;{print $2}&#039; )
on=$(echo $output &#124; awk &#039;{print $3&quot; &quot;$4&quot; &quot;$5}&#039; )
at=$(echo $output &#124; awk &#039;{print $6&#039;} )
echo &quot;User logged in from $ip on $on at $at&quot;&#124;mail -s &quot;Alert: user logged in to server $(hostname) from $ip&quot; ephrondiana@gmail.com
done

but its sending mail for root login only,i need to send mail for users login also.Please help me...</description>
		<content:encoded><![CDATA[<p>may be it was the wrong place to post this.Please help me,<br />
  I would like to send mail for each success login.i tried with this,<br />
and place this in /root/.bashrc<br />
#!/bin/bash<br />
echo `last $i | head -1 | awk &#8216;{print $1&#8243; &#8220;$3&#8243; &#8220;$4&#8243; &#8220;$5&#8243; &#8220;$6&#8243; &#8220;$7}&#8217;`|while read output;<br />
do<br />
echo $output<br />
ip=$(echo $output | awk &#8216;{print $2}&#8217; )<br />
on=$(echo $output | awk &#8216;{print $3&#8243; &#8220;$4&#8243; &#8220;$5}&#8217; )<br />
at=$(echo $output | awk &#8216;{print $6&#8242;} )<br />
echo &#8220;User logged in from $ip on $on at $at&#8221;|mail -s &#8220;Alert: user logged in to server $(hostname) from $ip&#8221; <a href="mailto:ephrondiana@gmail.com">ephrondiana@gmail.com</a><br />
done</p>
<p>but its sending mail for root login only,i need to send mail for users login also.Please help me&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vivek</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141832</link>
		<dc:creator>vivek</dc:creator>
		<pubDate>Mon, 12 Nov 2007 20:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141832</guid>
		<description>Nice suggestion, the post has been updated.</description>
		<content:encoded><![CDATA[<p>Nice suggestion, the post has been updated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Schroeder</title>
		<link>http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141831</link>
		<dc:creator>Jeff Schroeder</dc:creator>
		<pubDate>Mon, 12 Nov 2007 18:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.cyberciti.biz/tips/shell-root-user-check-script.html#comment-141831</guid>
		<description>Make error messages go to STDERR (Standard Error) like they do in other Unix programs. That is the best way to do things.

if [ &quot;$(id -u)&quot; != &quot;0&quot; ]; then
   echo &quot;This script must be run as root&quot; 2&gt;&amp;1
   exit 1
fi</description>
		<content:encoded><![CDATA[<p>Make error messages go to STDERR (Standard Error) like they do in other Unix programs. That is the best way to do things.</p>
<p>if [ "$(id -u)" != "0" ]; then<br />
   echo &#8220;This script must be run as root&#8221; 2&gt;&amp;1<br />
   exit 1<br />
fi</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.184 seconds -->
<!-- Cached page served by WP-Cache -->
