Issue in passing passwd to login into a sudo account

Hi Gurus,

I have small issue...
I used to pass the passwd for sudo commands like below,

 
gzcat ~/passwd.gz | sudo su - <villin> >> eof
------
-----
------
eof

And it was able to login into "villin" sudo account successfully. But now, I'm using the same in another script for the same sudo account login... It's not working now and I'm getting below error,
My script:

 
#!/bin/bash
CMD="sudo su - villin"
gzcat ~/passwd.gz | ${CMD} << eof1
sh New_report_dev.sh
eof1

Error:

Do I need to set any variable here to achieve this?
Can anyone please advice?

Regards,
VRN

---------- Post updated at 09:26 PM ---------- Previous update was at 08:03 PM ----------

Hello frnds,

I found the issue, but i need some more help...

Actually it's working for sometimes, nit working for sometimes...
But after logged into sudo account, the default shell is 'csh'. So after logged into this account, I'm trying to set some env variables. The syntax of setting variables and calling them inside csh is wrong...

 
#!/bin/bash
CMD="/usr/bin/sudo /bin/su - villin"
gzcat ~/code.gz | ${CMD} << eof1
echo "Logged into villin successfully"
#Once logged into this account, the default shell is 'csh' here.
set PATH1 = ~/pd/perl/prod/bin/perl
set PATH2 = ~/logs/temp
$argv[$PATH2] $argv[$PATH3]New_report_dev.pl
exit
eof1

It's unable to read those variables and the Perl script is not executing here...
Can anyone please have a look at the below my code and suggest on this?

Regards,
VRN

I'm not sure but I think it's because your var CMD is set to a string
"/usr/bin/sudo /bin/su - villin" <---- this is a string not a command

try this:

CMD=`/usr/bin/sudo /bin/su -villin`

Using backticks instead of double quotes. I'm still quite the beginner but that's my best guess.

HI,
Thank u vm for your reply..

Here the sudo command is working fine for sometimes...
The main issue in this script is: Once it's changed to sudo account 'villin', it's unable to set the variables 'PATH1 & PATH2'... because once the id is changed, it'll be in c shell.... And i dont have much idea abot setting up variables in cshell..

Can you/anyone please advice me on this?

regards,
VRN