KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Problem: sudo doesn't work in Shell Script Test.

 
Post new topic   Reply to topic    KS-Soft Forum Index -> RMA for UNIX
View previous topic :: View next topic  
Author Message
nieaicai



Joined: 03 Aug 2012
Posts: 73

PostPosted: Thu May 09, 2013 3:27 am    Post subject: Problem: sudo doesn't work in Shell Script Test. Reply with quote

Dear KS-Soft:
I changed rma(linux) file owner group and access permissions to the user "monitor",and start rma by this user:

-rwx-r-r-- 1 monitor monitor 809 2010-01-20 cpu.sh
-rwx-r-r-- 1 monitor monitor 12987 2012-10-23 INSTALL
-rwx-r-r-- 1 monitor monitor 4641 2012-10-23 LICENSE
-rw-r--r-- 1 monitor monitor 206 04-19 17:31 log.txt
-rwx-r-r-- 1 monitor monitor 787 2007-02-22 proccnt.sh
-rwx-r-r-- 1 monitor monitor 543 2007-02-22 proclist.sh
-rwx-r-r-- 1 monitor monitor 2996 2012-10-23 README
-rwx-r-r-- 1 monitor monitor 224268 11-19 20:50 rma
-rwx-r-r-- 1 monitor monitor 7709 04-19 12:17 rma.ini
drwxr-xr-x 2 monitor monitor 4096 05-09 15:53 tmp

And I use Shell Script(Linux) method to perform some tests.All command in my scripts can be executed by user "monitor".
Some scripts works fine,but the other scripts including command "sudo" does not work.

E.g.
=====================
#!/bin/sh
COMMAND=/opt/IBM_DS/client/SMcli

if [ $# -ge 2 ]
then
CTRLAIP=$1
CTRLBIP=$2

###HERE: sudo doesn't work!!!!!
RESULT=$(sudo $COMMAND $CTRLAIP $CTRLBIP -c "show storageSubsystem healthStatus;")

case "$RESULT" in
*failure*)
echo 'ScriptRes:Bad:Failure'
exit
;;
*optimal*)
echo 'ScriptRes:Ok:Optimal'
exit
;;
*)
echo 'ScriptRes:Unknown:Unkown response from SMcli'
exit
;;
esac

else
echo 'ScriptRes:Unknown:not enough parameters specified'
fi


=====================
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 11782
Location: USA

PostPosted: Thu May 09, 2013 4:39 pm    Post subject: Reply with quote

Yes, its hard to make sudo work.
Try command like
RES=$(sudo sh -c 'sudo -u root $COMMAND)

Also, please make sure sudo does not prompt for password. You may need to add line like
username ALL=NOPASSWD: ALL
into sudoers

Regards
Alex
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nieaicai



Joined: 03 Aug 2012
Posts: 73

PostPosted: Thu May 09, 2013 7:45 pm    Post subject: Reply with quote

Dear Alex,
Comment out the following line in sudoers,sudo works fine in Shell Script method.
#Defaults requiretty

Thanks for your help.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 11782
Location: USA

PostPosted: Fri May 10, 2013 8:32 am    Post subject: Reply with quote

Thank you for information

Regards
Alex
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> RMA for UNIX All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index