View previous topic :: View next topic |
Author |
Message |
nieaicai
Joined: 03 Aug 2012 Posts: 73
|
Posted: Thu May 09, 2013 3:27 am Post subject: Problem: sudo doesn't work in Shell Script Test. |
|
|
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 |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12807 Location: USA
|
Posted: Thu May 09, 2013 4:39 pm Post subject: |
|
|
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 |
|
|
nieaicai
Joined: 03 Aug 2012 Posts: 73
|
Posted: Thu May 09, 2013 7:45 pm Post subject: |
|
|
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 |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12807 Location: USA
|
Posted: Fri May 10, 2013 8:32 am Post subject: |
|
|
Thank you for information
Regards
Alex |
|
Back to top |
|
|
|