script for execution root commands

I need execute the command "rdate" from an user application.
Perhaps, it's possible from a script??.
If anyone knows another method please help me!
Who is Participating?
mliberiConnect With a Mentor Commented:
Your problem is, more generally speaking:
"How may I run a shell script with super user authority?"

The problem is that, for security reasons, all unix operating systems (I think) do not allow SUID scripting.

I solved the problem by writing a shell script compiler that allows you to generate an executable starting from a shell script. It don't represent a security risk because the compiled code can't be easily viewed or changed, so you are sure that the user do only what your program does.

The method is simple:
1) create your shell script (e.g.
2) compile it               (e.g. kcc
   the compiler will produce the executable 'xxx'
3) change 'xxx' ownership   (e.g. chown root xxx)
4) set SUID bit             (e.g. chmod u+s xxx)

Any user that run 'xxx' program would become root for the time the process is running.
Avoid forking programs that allows starting a shell, it would be a root shell!

You can download kcx - the shell script compiler from the following URL:

It has been compiled for AIX, SunOS, IRIX, Linux and Cygwin32
but could be easily compiled for any unix platform with an ANSI C compiler.

rdate can be run from a script, but it does require root privs to
run. Add the following lines to the script file:
/bin/rdate <hostname> (hostname is the name of the system that
has the correct time).

elmisterAuthor Commented:
How is possible to login in as root from a script (root with password, of course) for execution of rdate?
P.D I know the root password, of course.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

It's a security risk, but try this :

Create your script to run rdate like this:
#! /usr/bin/ksh
# Change to root user
su -
#run rdate
/bin/rdate mypc

Create a second script like this:

#! /usr/bin/ksh
# Run your rdate script
/ <<EOT
god    <-- This is your root password

You cannot rlogin from within a script, it always asks for passwd on stdin.
Why not using rsh?
elmisterAuthor Commented:
It doesn't work
It always asks for passwd on stdin
elmisterAuthor Commented:
Using rsh for rdate?
ray_leach suggestion didn't work on modern UNIX except you use a package called expect.

You may try to write a sucmd script as follows:

#! /bin/sh
exit 0

chmod u+s sucmd
chown root sucmd

Running this script may be restricted on most UNIXs, you have to patch the kernel then to allow suid-root-scripts (which is more
or less simple, refer to your docs).
If you are running on SCO,  then you can make that command a 'asroot ' command.  Essentially what that means is that there is a list of commands that can be ran regardless of the user.

for example:
/usr/bin/asroot shutdown -g0 -y -i6

this will for use in scripts. It is how I do it for most of our clients.
elmisterAuthor Commented:
I Haven't asroot command
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.