Crontab - password prompting

// Red Hat Enterprise Linux Server release 6.7

I wanted to pass the password, but when I execute this cron, it stops at

Password: 

prompt.

Please advise on how to fix the error. Thank you for tour help in advance.

#!/usr/bin/ksh
su - pmserver
echo "su - pmserver"
cd /cerner/d_prod/extract/archive
echo "cd /cerner/d_prod/extract/archive"
export SSHPASS=abcd1234
sshpass -e sftp -oBatchMode=no -b - sftp-root@piapp << !
cd /cerner/d_piprd/extract/landing
mput edw_*stats*.dat
sleep5
mput dw_*.dat
sleep 30
exit 
!
echo "exited"

su does not work that way, it does not run the lines after it when you put it in a shell script and does not belong in a script.

If you want to login without a password to run a command, configure sudo to allow this user to run this specific program as sudo. That'd be a line in sudoers something like

mycronuser pmserver=NOPASSWD: /path/to/myshellscript.sh

Then you can run in your cron line, sudo -u pmserver /path/to/myshellscript.sh

You don't need to use sshpass either, if you arrange keys between this computer and the ssh server.

1 Like

Thank you so much!