- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: C Scripting question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:14 AM
09-22-2004 05:14 AM
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.
The C program was design to allow only certain ids can execute it.
Is there a way to make this program work in cron.
Any helps is appreciated.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:23 AM
09-22-2004 05:23 AM
Re: C Scripting question
cron has no environment. You need to set up PATH and sometimes SHLIB_PATH to make certain programs work right.
If you just want to know who the user is, you can check the environment variable $LOGNAME
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:25 AM
09-22-2004 05:25 AM
Re: C Scripting question
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:30 AM
09-22-2004 05:30 AM
Re: C Scripting question
===========================================
The getlogin() function retrieves the name of the user currently
logged in on a terminal associated with the calling process, as found
in /etc/utmp.
At least one of the standard input, standard output, or standard error
must be a terminal. For the first of these found that is a terminal,
a user must have logged in on that terminal, and that terminal must be
the controlling terminal of the session leader process of the calling
process's session.
============================================
Remember there is no terminal attached to the cron jobs. That is the very reason why your getlogin() is not working.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:32 AM
09-22-2004 05:32 AM
Re: C Scripting question
Try this below code:
#include
#include
main ()
{
int user;
user=getlogin();
printf("Hello %s\n",user);
}
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".
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:46 AM
09-22-2004 05:46 AM
SolutionTry this
#include
#include
#include
main()
{
struct passwd *test;
test=getpwuid(getuid());
printf("User : %s\n",test->pw_name);
}
I am not good at C, so test it before you use :-).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 04:58 PM
09-22-2004 04:58 PM
Re: C Scripting question
Hi,
I'm not sure, but you can try it. Rather directly using the Program in the cron, add the entry in cron as following:
su -
Hope this helps.
regards,
Ravi B Hiremath
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2004 05:46 PM
09-22-2004 05:46 PM
Re: C Scripting question
See this program as,
# cat test.c
#include
#include
main()
{
char *user;
char *euser;
user=getlogin();
euser=cuserid(user);
printf ("USER=%s\tEUSER=%s\n",user,euser);
}
It will do it your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2004 05:06 AM
09-23-2004 05:06 AM
Re: C Scripting question
I am using solution provided by Sundar to resolve my problem.