<?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: C Scripting question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862109#M864784</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try this below code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;PWD.H&gt;&lt;BR /&gt;&lt;BR /&gt;main ()&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;int user;&lt;BR /&gt;&lt;BR /&gt;user=getlogin();&lt;BR /&gt;printf("Hello %s\n",user);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;If I the above code as oracle id from command prompt, it will return "Hello oracle". But if run it from cron, it will return "Hello".&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PWD.H&gt;&lt;/STDIO.H&gt;</description>
    <pubDate>Wed, 22 Sep 2004 12:32:23 GMT</pubDate>
    <dc:creator>Ridzuan Zakaria</dc:creator>
    <dc:date>2004-09-22T12:32:23Z</dc:date>
    <item>
      <title>C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862105#M864780</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;We have an exixting C program that use getlogin() fucntion to validate user who run the executable. The program run without any problem until we try to execute it from cron. It seems that getlogin() funtion will not return userid information if it run from cron. &lt;BR /&gt;&lt;BR /&gt;The C program was design to allow only certain ids can execute it.&lt;BR /&gt;&lt;BR /&gt;Is there a way to make this program work in cron.&lt;BR /&gt;&lt;BR /&gt;Any helps is appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Sep 2004 12:14:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862105#M864780</guid>
      <dc:creator>Ridzuan Zakaria</dc:creator>
      <dc:date>2004-09-22T12:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862106#M864781</link>
      <description>Seeing the code would be useful.&lt;BR /&gt;&lt;BR /&gt;cron has no environment. You need to set up PATH and sometimes SHLIB_PATH to make certain programs work right.&lt;BR /&gt;&lt;BR /&gt;If you just want to know who the user is, you can check the environment variable $LOGNAME &lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Wed, 22 Sep 2004 12:23:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862106#M864781</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-09-22T12:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862107#M864782</link>
      <description>When run by cron, it will take the userid of the crontab entry's owner.  Whose crontab is this?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Wed, 22 Sep 2004 12:25:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862107#M864782</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2004-09-22T12:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862108#M864783</link>
      <description>hmm...you are not using the right system call :-)&lt;BR /&gt;&lt;BR /&gt;===========================================&lt;BR /&gt;The getlogin() function retrieves the name of the user currently&lt;BR /&gt;      logged in on a terminal associated with the calling process, as found&lt;BR /&gt;      in /etc/utmp.&lt;BR /&gt;&lt;BR /&gt;      At least one of the standard input, standard output, or standard error&lt;BR /&gt;      must be a terminal.  For the first of these found that is a terminal,&lt;BR /&gt;      a user must have logged in on that terminal, and that terminal must be&lt;BR /&gt;      the controlling terminal of the session leader process of the calling&lt;BR /&gt;      process's session.&lt;BR /&gt;============================================&lt;BR /&gt;&lt;BR /&gt;Remember there is no terminal attached to the cron jobs. That is the very reason why your getlogin() is not working.&lt;BR /&gt;&lt;BR /&gt;Use getuid() to get the userid and pass it on to the getpw() to get the username and then compare with the allowed list of usernames.</description>
      <pubDate>Wed, 22 Sep 2004 12:30:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862108#M864783</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-22T12:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862109#M864784</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try this below code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;PWD.H&gt;&lt;BR /&gt;&lt;BR /&gt;main ()&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;int user;&lt;BR /&gt;&lt;BR /&gt;user=getlogin();&lt;BR /&gt;printf("Hello %s\n",user);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;If I the above code as oracle id from command prompt, it will return "Hello oracle". But if run it from cron, it will return "Hello".&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PWD.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 22 Sep 2004 12:32:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862109#M864784</guid>
      <dc:creator>Ridzuan Zakaria</dc:creator>
      <dc:date>2004-09-22T12:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862110#M864785</link>
      <description>As I said above, getlogin() will not work when the process is not attached to a terminal.&lt;BR /&gt;&lt;BR /&gt;Try this&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;PWD.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;  struct passwd *test;&lt;BR /&gt;  test=getpwuid(getuid());&lt;BR /&gt;  printf("User : %s\n",test-&amp;gt;pw_name);&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;I am not good at C, so test it before you use :-).&lt;/UNISTD.H&gt;&lt;/PWD.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 22 Sep 2004 12:46:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862110#M864785</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-22T12:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862111#M864786</link>
      <description>&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt; I'm not sure, but you can try it. Rather directly using the Program in the cron, add the entry in cron as following:&lt;BR /&gt;&lt;BR /&gt;su - &lt;USER&gt; &lt;C program="" or="" command=""&gt; &lt;IT&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;Ravi B Hiremath&lt;/IT&gt;&lt;/C&gt;&lt;/USER&gt;</description>
      <pubDate>Wed, 22 Sep 2004 23:58:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862111#M864786</guid>
      <dc:creator>RAVI B. HIREMATH</dc:creator>
      <dc:date>2004-09-22T23:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862112#M864787</link>
      <description>We can getlogin and cuserid call for this too. Zakaria you tried wrongly with int there.&lt;BR /&gt;&lt;BR /&gt;See this program as,&lt;BR /&gt;# cat test.c&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt; char *user;&lt;BR /&gt; char *euser;&lt;BR /&gt;&lt;BR /&gt; user=getlogin();&lt;BR /&gt; euser=cuserid(user);&lt;BR /&gt;&lt;BR /&gt; printf ("USER=%s\tEUSER=%s\n",user,euser);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;It will do it your requirement.&lt;/STDIO.H&gt;&lt;/UNISTD.H&gt;</description>
      <pubDate>Thu, 23 Sep 2004 00:46:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862112#M864787</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-23T00:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: C Scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862113#M864788</link>
      <description>Thanks to those you have response to my questions.&lt;BR /&gt;&lt;BR /&gt;I am using solution provided by Sundar to resolve my problem.</description>
      <pubDate>Thu, 23 Sep 2004 12:06:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-scripting-question/m-p/4862113#M864788</guid>
      <dc:creator>Ridzuan Zakaria</dc:creator>
      <dc:date>2004-09-23T12:06:40Z</dc:date>
    </item>
  </channel>
</rss>

