473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Switching Unix user in unattended Perl script

Hi folks!

I need to find a way to switch to a different Unix user from within
the Perl script that is currently ran unattended. Script must switch
user in order to execute proper profile for different Data Base
Instance and set corresponding environmental variables correctly.
Script works fine for a single Data Base Instance. I need to be able
to run it consecutively for several others instances. This requires
login in as a different Instance Owner.

I don't have (and don't need to have!) root privileges to run the
script. How can I switch to a different user without having script
prompting me for entering password? I have all login credentials so I
just need to switch user by supplying username and password.

Any help would be greatly appreciated.

Thanks!

D.
Jul 19 '05 #1
2 8978
On Wed, 24 Sep 2003 14:53:17 -0700, Dmitry wrote:
Hi folks!

I need to find a way to switch to a different Unix user from within
the Perl script that is currently ran unattended. Script must switch
user in order to execute proper profile for different Data Base
Instance and set corresponding environmental variables correctly.
Script works fine for a single Data Base Instance. I need to be able
to run it consecutively for several others instances. This requires
login in as a different Instance Owner.

I don't have (and don't need to have!) root privileges to run the
script. How can I switch to a different user without having script
prompting me for entering password? I have all login credentials so I
just need to switch user by supplying username and password.


I would be very surprised to discover that you can do this in perl
without running as root. Are you sure that this is the right solution? I
would look into using expect, if you have it installed. It typically
comes with another program called autoexpect which will generate a script
for you, which you should then trim down.

Here is my general purpose 'do something as someone else' script:
(If you've never ssh'ed to localhost, do it at least once before running
this in order to accept the key.)

An even better option is to set up the ssh keys so that you don't even
need to supply a password, or use expect. You can just shell out within
your master program to run:
`ssh -l $user localhost run-this-as-another-user.pl '$param1' '$param2'`

------------------------------------------------
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set user [lindex $argv 0]
set pass [lindex $argv 1]
set arglist [lindex $argv 2]
for {set i 3} {$i < $argc} {incr i +1} {
set arglist "$arglist [lindex $argv $i]"
}

set timeout -1
spawn ssh -l $user localhost $arglist
#the reason I use ssh is so that I
#don't have to guess what the user's
# prompt looks like in order to know
#when the command completed

match_max 100000
expect "assword: "
send -- "$pass\r"
expect eof

Jul 19 '05 #2

"Dmitry" <pe******@optonline.net> wrote in message
I need to find a way to switch to a different Unix user from within
the Perl script that is currently ran unattended.


Could you set up ssh authorized keys for each user and do it that way?

Just a thought

Dale
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
2
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
0
by: Danny Jensen | last post by:
I need to test if certain processes on a unix box were running. I wanted to use whatsup gold to do the testing. First I needed to go to the whatsup configure>monitors & services menu to add this...
1
by: Thierry Missimilly | last post by:
Hi Postgres users, I wonder to know if it is possible to launch a Perl program or a unix comand in a trigger function. I have tried to do that in a C trigger developed with the SPI function....
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
4
by: nidhikhandelwal | last post by:
I am calling a unix shell script from a perl script by using the following system command: system("./readfile_new.sh"); but it seems the unix script readfile_new.sh is not being called. Can...
2
by: sunilsn | last post by:
Hi, I am newbie to perl, I hope you guys will help me resolve the challenge I am facing. I have a unix shell script on one UNIX machine say A, and a batch file on windows machine say B. Now I want...
4
by: jane007 | last post by:
Hello everybody: I am having a problem. On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from Windows, these is an issue occurs,...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.