Bug 468 - For loop not working when sudo in shell script
For loop not working when sudo in shell script
Status: RESOLVED INVALID
Product: Sudo
Classification: Unclassified
Component: Sudo
1.8.0
PC Other
: low normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-02-18 17:04 MST by Abdul
Modified: 2011-02-20 13:42 MST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abdul 2011-02-18 17:04:35 MST
Do you know why the script is not working when sudo another user within the shell script, which has a loop? I tried below two examples, both didn't work. My user1 doesn't need password for sudo to user2, we have already set up that. The sudo works when there's no loop. But example-3 woks well.
Example1:-
=================
#!/usr/bin/ksh
echo "Script started" > $LOG_FILE
for i in `ls nyt_sartre_*.gpg`
do
   sudo su - user2 << EOF
   mv -f $pgpfn $actual_fn  
   rc=$?
   EOF
done
echo "Script completed" >> $LOG_FILE

Example2:-
=================
#!/usr/bin/ksh
echo "Script started" > $LOG_FILE
for i in `ls nyt_sartre_*.gpg`
do
   sudo su - user2 << EOF
   mv -f $pgpfn $actual_fn  
   rc=$?
   EOF
done
echo "Script completed" >> $LOG_FILE

Example3:-
=================
# This works well
#!/usr/bin/ksh
echo "Script started" > $LOG_FILE
   sudo su - user2 << EOF
   mv -f abc.txt $home/backup/  
   rc=$?
   EOF
echo "Script completed" >> $LOG_FILE
Comment 1 Todd C. Miller 2011-02-20 13:42:39 MST
This is not a bug in sudo.  Please send questions like this to the sudo users mailing list, sudo-users@sudo.ws