how to connect to admin accout through script

hi everyone
i'm running script in c-shell and i want this script to connect to admin account in order to run other script in k-shell. after that i want the script to be severed from the admin account and to continue with the regular commands
example:
my script call cs-customers
echo"starting to search for customers files"
login:admin
passwd:
ksh cs-search
#disconnect from the admin account
if test -s b.log
........
fi
the problem is that the script stop because he need the passwd of the admin
how can i do this or fix such a script that he won't stop ?
of course the script in c-shell and the script in k-shell are running in different
directories

Hi.
You could use ssh to yourself (with certificates to avoid interaction) or you could use the tool "sudo" (http://www.courtesan.com/sudo/intro.html\)
Regards.

thanks for the quick response
i didn't get the idea of sudo should i build these as different file ?
does someone have any other solution ?
please help
best regards

Well, if you want to execute everythig in the same server, I would chose sudo.
In this case, youo should install the tool and configure it for your needs using "visudo"
You would add a line like this:

user ALL=NOPASSWD:/path/to/cs-customers

"user" is the user who executes the initial script, and "/path/to/cs-customers" is what you want this user to execute as root. The script then would be:

echo"starting to search for customers files"
sudo /path/to/cs-customers
if test -s b.log
........ 
fi

Finally, If the initial script is in one server and the second in another, you should consider using ssh with digital certificates for authentication so that you won't need to enter root's password. Though you could automate a telnet session. There are a couple of threads about this in this forum.

Regars

hi everyone
i try to do something like this
i go to the admin account (root) and did
id
giving me
uid=0(root) gid=1(other)
now in the first script cs-customers i did something like this
echo"starting to search for customers files"
login:root
password:
#id
uid=0(root) gid=1(other)
ksh cs-search
#disconnect from the admin account
if test -s b.log
........
fi
question 1 .is it true to write like this
2. my goal is not to touch any of the .login or /etc/host file
i just want to connect to root because if the script and then disconnect from it . i want to connect to root without passwd only when i running the cs-customers . is it correct what i wrote???
thanks all for quick response

Are both scripts in the same machine? If so, why do you want to do such a thing???
I'm afraid I do not understand you...

hi
first according to your reaction i'm hope i didn't cause any harm
please currect me if i'm wrong i didn't change anything in any system files or something however let me explain again
i'm working in the same machine in this machine i have several users and
directories some of them are c-shell and some k-shell
i have problem because when i'm running script in c-shell cs-customers) it start to
perform object in cobol which going through several directories and
reading files . the problem is :
while i'm running the script above (cs-customers) he cannont read the files because i need to change their premissions.problem i need to connect to root
account (in the same machine) and change premissins of those files.
from my point of view i realy do'nt care if i need to run 2 different script bacause i still in the same problem ,if i have script i need to su him to root account for changing mod of files
any solutions
i think that might be here easy solution because i'm working abount one machine all the time

I'm sorry If you felt I had a bad reaction. Don't misunderstand me, that's not the case :slight_smile:

As I told you before, I would use either of:

hi grial
it's o.k i just freek out i thought that i did something wrong
look you need to help me here because i did not realy understand how to do the first thing "sudo" shell i change system file for this , bacause if that so
i'm realy don't want so much to do this is there any other way?
2. the link that you attached to me i do'nt know what is the ip how shel i know that? besides it's look like a script to connect to other machine while i'm working at the same machine all the time
is there any other way to write the passwd it the same script to variable and he will connect such as :
"starting to search..."
bsd="root123"(passwd of root)
su root
passwd =$bsd
.
.
.
is there any way to do this ?
thanks for quick response

Well, if you don't want to use sudo, try this:

# The IP is loopback, so that you connect to yourself.
IP=127.0.0.1
UNAME=root
PWD=rootpassword
echo "Connecting to $IP as root..."
(
    sleep 2 
    echo "$UNAME"; sleep 2
    echo "$PWD"; sleep 2
    echo "ksh cs-search"   # Commands here.
    sleep 2
) | telnet "$IP"
echo "End of root session."
if test -s b.log
........ 
fi
........

I hope this is what you want.

i'm sorry grial you have to be very patient with me bacause
i didn't understand how i know my ip ? is there any command that display all this ? and if you be so kind to explain me a little bit about the script what is exactly the talnet ?
when you wrote connecting to yourself you mean " because i'm working on the same machine" write?
thaks a lot for being patient and for quick response

You do not need to know your IP in this case. But if you want to, execute:

ifconfig -a

I think you should have a look to some tutorials and manuals about unix (and networking)... :slight_smile:

hi grial thank you thank you ....... itws work :slight_smile:
i just want to understand if i donwt need the ip how should i do that
i wrote
UNAME=root
PWD=cnfg777
(
sleep 2
echo "$UNAME"; sleep 2
echo "$PWD"; sleep 2
ksh cs-search
sleep 2)
(without telnet) i see that is not run the cs-search
question 2 :
after he finishing the cs-search he comeback to the script and enviroment that call to him ?
question 3 :(this is the last question)
if i have other users in the system and all of them ofcourse working on the same machine it's not disturber them right ?
it's behaving regular as if i was doing this process not automaticly?
thaks for huge help and for great patient!!!
you're rock!!!

It's a bit difficult for me to understand you... You need to improve your english... :slight_smile:
If

UNAME=root
PWD=cnfg777
(
sleep 2
echo "$UNAME"; sleep 2
echo "$PWD"; sleep 2 
ksh cs-search
sleep 2)

works it means you are executing as root and it's nonsense to execute such a thing. So:

ksh cs-search

alone will also work...
The code I posted before will work if you are executing the first script as a "normal" user and want "cs-search" run as root.

One more thing: Do not post your real user and password!

ho grial
don't worry itws not the original login and passwd i'm not that...........
besides
i just wanted to say that if i'm working in the same machine i realy don't need
to write the ip
what i try to explain is that when i wrote the ip
it's connect to the root and run cs-search and when i give up on the ip
it's seems like it's not run the cs-search script
that's why i asked this question from the first place
but thanks for the patient and for huge help

hi everyone
i'm repeating on my question if anyone can help here please do so.
i can't understand according to what i wrote :
why if i'm working at the same machine
and i'm trying to connect through script from one account to other account
i need to write the ip address ?why if i'm writing to him only the login and
passwd he can't connect to the account
UNAME=amber1
PWD=(amber passwd)
(
sleep 2
echo "$UNAME"; sleep 2
echo "$PWD"; sleep 2
ksh cs-search
sleep 2)
the script did not connect to the amber account

note :
i'm deliberately used in the last example that i'm connecting to
other account (user amber) because this user
and the user that i'm running the script from him both of them are
define as c-shell enviroment