Execute .sh file with sudo in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute .sh file with sudo in it
# 1  
Old 06-13-2008
Execute .sh file with sudo in it

Hi,
I logged into a UNIX system as user ABC.
I do not have root previleges and also do not have root password.

I am executing few commands as:
ABC****>sudo su - XYZ
XYZ****>rm file1.txt
XYZ****>exit
ABC****>

Now I want to execute all these commands from a .sh file ( or in any other way). I put all these commands in a test.sh and executed as

ABC****>./test.sh

the problem here is that , only first command is executed and control is gone to
XYZ****>

When I entered exit as
XYZ****>exit

the remaining commands in the test.sh started the execution as

ABC****>rm file1.txt
No Permission.
ABC****>exit

How should I execute the "rm file1.txt" as a XYZ user?
# 2  
Old 06-13-2008
Why don't you invoke find to get the names of every file you are going to want to delete, park the name in a script, sudo to XYZ, run the script.

Or sudo to XYZ ,cd to the directory with a problem, then
Code:
chown -R ABC *

You will see lots of errors for files XYZ does not own. But now all of XYZ's files in the whole directory tree belong to ABC.
# 3  
Old 06-13-2008
no luck

I did this, but got this error :
Permission denied
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

2. Shell Programming and Scripting

How to execute command remotely as sudo and save the output locally?

Hello , I am trying to run a NetBackup command in remote server. Also this command can only be run by root so I am using sudo . Also I want the output of the command locally in a file. The below command asked for password , ran successfully and showed Output on my local server screen ... (2 Replies)
Discussion started by: rahul2662
2 Replies

3. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi, Have a need to run the below command as a "karuser" from a java class which will is running as "root" user. When we are trying to run the below command from java code getting the below error. Command: sudo -u karuser -s /bin/bash /bank/karunix/bin/build_cycles.sh Error: sudo: sorry,... (8 Replies)
Discussion started by: Satyak
8 Replies

4. Solaris

How to copy over sudo file

Dear all, I am working on a Solaris 10 (x86 box), trying to copy over the sudo file. I get the folowing error: #cp -p /usr/nbox/install/x86/sudo /bin cp: cannot create /bin/sudo: Read-only file system I appreciate any information you can share with me. (2 Replies)
Discussion started by: Hossein Beyzavi
2 Replies

5. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi All, I running a unix command using sudo option inside shell script. Its working well. But in crontab the same command is not working and its throwing "sudo: sorry, you must have a tty to run sudo". I do not have root permission to add or change settings for my userid. I can not even ask... (9 Replies)
Discussion started by: Apple1221
9 Replies

6. Red Hat

Sudo to execute script without passwd[solved]

Hi Hope someone can sched some light i'm trying to execute a script via sudo but i don't want to be prompted for a password when i run the script using sudo my sudo entry does work in that the script gets executed but i'm having to give a password, my current entry is given below user1 ... (0 Replies)
Discussion started by: duckeggs01
0 Replies

7. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

8. AIX

sudo log and sudo auditing

Sudo In AIX, how to find out what commands have been run after a user sudo to another user? for example, user sam run 'sudo -u robert ksh' then run some commands, how can I (as root) find what commands have been run? sudo.log only contains sudo event, no activity logging. (3 Replies)
Discussion started by: jalite19
3 Replies

9. UNIX for Dummies Questions & Answers

Unable to use the Sudo command. "0509-130 Symbol resolution failed for sudo because:"

Hi! I'm very new to unix, so please keep that in mind with the level of language used if you choose to help :D Thanks! When attempting to use sudo on and AIX machine with oslevel 5.1.0.0, I get the following error: exec(): 0509-036 Cannot load program sudo because of the following errors:... (1 Reply)
Discussion started by: Chloe123
1 Replies

10. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies
Login or Register to Ask a Question