Help with sudo in shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sudo in shell scripts
# 1  
Old 09-23-2008
Help with sudo in shell scripts

hi,
I have a script abc in a machine xyz. which i can access by sudo su - user. that is i can login to xyz using my id and then switch to user and run the script.

Now what i need to do is run the script from another script in machine xyz1. From xyz1 i can ssh to xyz using my id. Some one please help me in doing this.

thank you

Last edited by rvz; 09-23-2008 at 03:40 AM..
# 2  
Old 09-23-2008
You can do this without having to do the sudo bit, it can be a bit tricky and the man page is a pain to read...

Instead, create some ssh-keys for your user on xyz1. copy the public key to the target user's .ssh directory in in home dir, into the file authorized_keys.

Now ssh as the user on xyz1 using the shiny new private key to xyz and run the script:

ssh -i /path/to/shiny/new/priv_key theotheruser@xyz "/path/to/your/script.sh"

Hope this helps a bit.

Another thing- it will make it easier if you could be a little less cryptic in your question- instead of hosts xyz and xyz1, users user and id you could just give them some names:

I have a script evilscript.sh accessable by eviluser on machine avalon. I have another user called bob on avalon as well. The user bob exists on machine houston.

I want my user bob on houston to log onto avalon then, using sudo, run script evilscript.sh as user eviluser.

Smilie makes it a bit easier for people to help you.

/fimblo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sudo password in shell file

Hi all, I have a script like this, where i am trying to login into oracle db via ssh and do a account unlock. #!/bin/sh ip=$1 os_user=$2 key=$3 ou_user=$4 ou_pass=$5 unlock_user=$6 ssh -i $key $os_user@$ip sudo -u $ou_user -p $ou_pass -- i am getting error here...its not taking... (16 Replies)
Discussion started by: onenessboy
16 Replies

2. Shell Programming and Scripting

Problem connect to a different server then do sudo login and finally run some scripts and get result

I have to write a shell script in my current linux server and I have to connect to a different server then do sudo login and finally run some scripts residing in a particular directory and get results back. I am starting to write my shell script as below but after I do ssh login it prompts for... (2 Replies)
Discussion started by: Devesh5683
2 Replies

3. Shell Programming and Scripting

sudo scripts conundrum

hello; Got a problem running monitoring scripts using sudo ssh.. Mgmt decided to take away root sudoers access.. so most of the scripts ran as: sudo ssh $BOX ... Now I need to run them as: echo $my_pw | sudo -S -l my_user_id $BOX ... I tried this but not working.. Any wisdom/tricks... (3 Replies)
Discussion started by: delphys
3 Replies

4. Cybersecurity

Running Scripts With Parameters with sudo

Hello everyone, I'm new to the community so please bear with me if my terminology is not correct... I'm trying to configure /etc/sudoers so a specific user can run a script as root. My problem is I want to lock down what parameters the user can run the script against. The script in... (2 Replies)
Discussion started by: cyphex
2 Replies

5. Shell Programming and Scripting

Help with Shell Script on sudo

I want to execute a script(generateReport.sh) which resides on root home directory from shell script(localtrigger.sh) as root by using sudo. The thing is i cant edit /etc/sudoers (i can but m not allowed to do it , ethically) i cant change ownership of generateReport.sh script When i try... (7 Replies)
Discussion started by: saket
7 Replies

6. Shell Programming and Scripting

sudo su - user in a shell script

Normally i would google, but I did not know how to google the problem I am facing now also being a newbie in shell scripting. Okay, the requirement is user1 has sudo rule to su - user2(NO PASSWORD) and user2 has will be able to sudo certain commands so following works fine from command prompt... (2 Replies)
Discussion started by: beEnthu
2 Replies

7. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

8. Solaris

shell variable not following through with sudo

Good morning.. ok, so I have 2 desktops that are supposed to be built VERY similar. They both have solaris 10 installed on them. I have a specific user that is trying to pass variables through using sudo. He already has this variable set.. tmp=/home/useraccount/tmp However when he does:... (1 Reply)
Discussion started by: s ladd
1 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. UNIX for Dummies Questions & Answers

sudo in OS X shell script without password prompt??

I've written a shell script to alter a particular preference file on OS X (10.3.9), which works fine (tested by running the script from the terminal sat in front of the box). Problem is, I now have to run this script remotely across a number of machines via remote desktop, so where I've used the... (1 Reply)
Discussion started by: Brad_GNET
1 Replies
Login or Register to Ask a Question