Operating System - HP-UX
1834208 Members
2637 Online
110066 Solutions
New Discussion

Re: Help with expect scsript, running as a cronjob

 
Gangadhar_1
Occasional Advisor

Help with expect scsript, running as a cronjob

Hi all, I am trying to transfer a file using SFTP, using an expect script.

Following is the expect script that i have kept in crontab file:
===========================
#!/usr/local/bin/expect
spawn sftp -b /home1/purifyte/gangadhar/new/cmd ganga_k@172.16.2.25
expect "password:"
send "pass123\n";
interact

and the "cmd" file content is as follows:
=========================================
lcd /home1/purifyte/gangadhar/new/
put testfile /users/spv/gangadhar/testfile
bye

The thing is, if i run the expect script from command prompt, its running nicely, and i am getting the file in dest machine.
But when i keep it in crontab file, the file is not at all getting transferred.

Please help me ASAP. Its urgent.

Thanks in advance.
7 REPLIES 7
Ivan Krastev
Honored Contributor

Re: Help with expect scsript, running as a cronjob

Set your PATH before executing commands, or use full pathname - for example /usr/bin/sftp.


regards,
ivan
Yang Qin_1
Honored Contributor

Re: Help with expect scsript, running as a cronjob

Hi, did you check /var/adm/cron/log?

#!/usr/local/bin/expect
spawn /usr/bin/sftp -b /home1/purifyte/gangadhar/new/cmd ganga_k@172.16.2.25
expect "Password:"
send "pass123\r"

Remove that "interact" because you don't want to run it interactively.

Yang
Gangadhar_1
Occasional Advisor

Re: Help with expect scsript, running as a cronjob

@Ivan Krastev
Thanks for your reply but i have given full path only.

@Yang Qin
Thanks for your reply but that "interact" doesn't mean that its taking the inputs interactively.
It'll come out without taking the password if we don't give the "interact" in expect script.

Any other solutions plz.
Yang Qin_1
Honored Contributor

Re: Help with expect scsript, running as a cronjob

It works fine for me. Did you find something in /var/adm/cron/log? Did you redirect the errors to a log for that cronjob? I just try to understand what was wrong (from which step ... or the script didn't run at all).

Yang
spex
Honored Contributor

Re: Help with expect scsript, running as a cronjob

Hi,

/home1/purifyte/gangadhar/new/
/home1/purifyte/gangadhar/new/cmd
/home1/purifyte/gangadhar/new/testfile

Is the user you cron'd the job under the same as the one you manually ran the script under? If not, ensure that he/she has +rx for the dir and +r for the files. Make sure the user appears in /var/adm/cron/cron.allow.

Also make sure $SHLIB_PATH and other environmental variables are set correctly in non-interactive mode. This can be accomplished through a wrapper script.

If you are still stuck, please post your revised scripts (using absolute paths).

PCS
OldSchool
Honored Contributor

Re: Help with expect scsript, running as a cronjob

Try running it as an "at" job once. If it works properly, then the issue is the environment. As noted above, and on lots of other posts regarding cron job failures, the environment is extremely sparse in cron. For example, you DONT have the complete path to sftp in the script...
Gangadhar_1
Occasional Advisor

Re: Help with expect scsript, running as a cronjob

Hi all,

i tried running it in background, by putting '&' at the end of the script. Now i got to know that it can't run in the background.

As per my knowledge, any process which needs interactive input, can't run in background. In this case, ultimately it needs input from standard input, we are givin it by using "expect script". So it can't run in the background.

Plz let me know if i am wrong somewhere, or in case of better answers.

Regards,
Gangadhar