HOw can i use sudo in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HOw can i use sudo in a script
# 1  
Old 03-29-2008
HOw can i use sudo in a script

Hi Everyone,

i am writing a script which will display all channels as below

sudo /usr/bin/su - mycamqrd
chs

I kept the above two lines in a ksh and after ran that it is going to mycamqrd home dir(sudo /usr/bin/su - mycamqrd).. The script is coming out and it is not executing chs. Please help me out in this.
Smilie

Thanks:
# 2  
Old 03-29-2008
Code:
sudo -u mycamqrd chs

I suppose you imagine the chs would be executed inside the sudo. It's not; your command runs a shell as root (!) and when you exit that, the chs will be executed as the current user.

If you really have a good (pressing! unreasonable!) reason to want to start a root shell and only execute chs in that, try this.

Code:
sudo -u mycamqrd -i -s chs

# 3  
Old 04-01-2008
Hi when i tried the above two commands it is asking for a passoword

Hi when i fired the above two commands it is asking me the password for mycamqrd. I am not running this from root shell as i dont have root permissions. Since i am firing the "sudo su - mycamqrd" and chs seperately i am getting the channels out put.

Please advise me how can i use the below two lines in ksh script.
sudo su - mycamqrd
chs


Smilie

Thanks in advance
# 4  
Old 04-02-2008
Quote:
Originally Posted by rajesh212512
Hi when i fired the above two commands it is asking me the password for mycamqrd. I am not running this from root shell as i dont have root permissions. Since i am firing the "sudo su - mycamqrd" and chs seperately i am getting the channels out put.

Please advise me how can i use the below two lines in ksh script.
sudo su - mycamqrd
chs


Smilie

Thanks in advance


Hi There! it should be
Quote:
sudo -u "username" command

make sure the NOPASSWD option in the sudoers files for that particular command is set or else your script will need you to input the password for the specified user.

Hope this helps
# 5  
Old 04-02-2008
please let me know

Please let me know what is the path/file name to check NOPASSWORD option is set or not for sudoers.

Thanks in advance
# 6  
Old 04-03-2008
Read the manual page for sudo, in particular the FILES section, where it tells you this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sudo for full script

All, When enabling sudo to run a script as root (install scripts, etc), is it required to enable sudo on all the actions/commands in the script or simply on the script itself and everything will run as root? Thanks in advance, HB (3 Replies)
Discussion started by: hburnswell
3 Replies

2. Shell Programming and Scripting

Script help on sudo access validation

hello I need help on this. The input is this. server system account name DBA account name x a p y b q z c r so i would like to check the sudo of the user is done or not. this is what i do to check it 1. login as root on server x 2.... (2 Replies)
Discussion started by: Kiran008
2 Replies

3. Shell Programming and Scripting

SUDO command in script

hi, can some one explain the sudo -n equivalent in AIX Thanks Venkat K (5 Replies)
Discussion started by: venky.b5
5 Replies

4. Shell Programming and Scripting

Need a script for sudo, login and output

Hello All , Hope everyone is doing great ! can someone help me for the below problem statement with the help of a script . 1. I am having couple of Linux Servers a. I need to login and need to do a sudo b. need to give a user id , which will take to user directory`s homedirectory... (1 Reply)
Discussion started by: radha254
1 Replies

5. Shell Programming and Scripting

How to run sudo commands under a script?

Hi, I am new to scripting. I am trying to write a script to ssh one remote machine and run a sudo command. ssh <hostname> sudo -S <command> < ~/pass.txt I am stored my password in pass.txt. I am getting error sudo: no tty present and no askpass program specified Please suggest me how can... (1 Reply)
Discussion started by: venkia9
1 Replies

6. 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

7. 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

8. Shell Programming and Scripting

password in sudo script

salmo allikm warhmat allah wabrakato i want to do script with sudo like sudo su and want to put password in the script not get from user because i to made it startup when booting and i don't know how put in script for sudo thanks (5 Replies)
Discussion started by: pua06
5 Replies

9. Shell Programming and Scripting

sudo chmod not working through script

Legends, I am trying sudo chmod from one shell to different machine. but getting the error. Please let me know if there is any way to do this. A#pk} for i in Bl1 Brl1 >> do >> echo $i >> ssh $i sudo chmod 755 /etc/services >> done Bl1 Password: bash: sudo: command not found ... (2 Replies)
Discussion started by: sdosanjh
2 Replies

10. Shell Programming and Scripting

problem with sudo su and .sh script

here is my script: #!/bin/sh cd /Users/a echo "what is the name of the file u want?" read var1 var1=$var1... (1 Reply)
Discussion started by: cleansing_flame
1 Replies
Login or Register to Ask a Question