Bugzilla – Bug 468
For loop not working when sudo in shell script
Last modified: 2011-02-20 13:42:39 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
This is not a bug in sudo. Please send questions like this to the sudo users mailing list, sudo-users@sudo.ws