expect + cronjob + SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect + cronjob + SFTP
# 1  
Old 06-18-2008
expect + cronjob + SFTP

Hi all, i got a really strange problem

i wrote a script, when i run this script manually everything works fine
but when i make a cronjob for it, with the same user, the EXPECT script will not work.
Only the first line will be executed

this is the SHell bash script
Code:
#!/bin/sh;
php -q /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export.php > /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export_php.log;
sleep 5
/usr/bin/expect /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export.exp > /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export_transfer.log;

this is the EXPECT script
Code:
#!/usr/bin/expect

spawn sftp -o port=10022 -b /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/batchfiles/export.batch user@host:incoming

expect "user@'s password:" 

send "\r"

interact

i really hope someone can give me a sollution, i am trying for 2 months to fix this
# 2  
Old 06-18-2008
not going to ask about running php at CLI but i think the way you're calling the expect script is wrong

May be better to call it like this

/home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export.exp > /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/export_transfer.log 2>&1

in the start of the script you're already telling it to use 'expect', no need to tell it twice. I assume the script does actually work via CLI, right ?


p.s it's a shell script not a bash script
# 3  
Old 06-18-2008
i'll try that

everything works except the expect script.
when checking the log file i get this
Code:
spawn /usr/bin/sftp -o port=10022 -b /home/tsjingcom/HTML/consumentbeheer/files_cassis/scripts/batchfiles/export.batch user@host:incoming
user@host's password:

but when i start the shell script manually it works, i really don't know why this happens
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to do SFTP using expect

Hi, I am trying to sftp using expect, but not getting through as it prompt for password is coming Following is the code #/usr/bin/expect > output.log sftp medcdr@10.130.254.50 expect "password:" send "Med@Cdr12\n" expect "sftp>" send "put ZTE_*201505*\r" expect "sftp>" send "bye\r"... (7 Replies)
Discussion started by: siramitsharma
7 Replies

2. Shell Programming and Scripting

expect telnet script execute by cronjob

hi, please help, keep getting this bolded error and look it up and people say its your environment variable though i tried to set it manually in expect..it run fine if i run it manually but once i run it by cronjob it error below..i tried to comment out ip/login info with *.. logfile:: START... (0 Replies)
Discussion started by: cssanangeles
0 Replies

3. Shell Programming and Scripting

Expect Script for SFTP Upload

I am attempting to utilize an expect script (that is called from a parent bash script) to perform a file transfer over sftp. The script works except I cannot catch timeouts. I need to be able to tell in the parent bash script when the expect script has timed out, or completed successfully. It... (3 Replies)
Discussion started by: thaller
3 Replies

4. Shell Programming and Scripting

Expect script cronjob running but dying prematurely

I have an Ubuntu machine that I'd like to update automatically. I've written an expect script to run the aptitude package manager and update my packages. Essentially it does: aptitude update && aptitude upgrade while answering "yes" at the appropriate time. It works quite nicely when run... (4 Replies)
Discussion started by: CluelessPerson
4 Replies

5. Shell Programming and Scripting

Using expect to automate sftp

I am trying to use a for loop in my expect cmdFile that I am calling. I want to be able to call either one file name or a series of file names in the working directory (that I won't know the names before hand) and then pass the names to the sftp program. Something like for i in (ls *txt) do (0 Replies)
Discussion started by: vedder191
0 Replies

6. Shell Programming and Scripting

sftp expect timeout problem

hello All, I am doing SFTP using expect. We just change our server from sun solaris 8 to sun solaris 10. The script was working good on sun solaris 8. But it is giving problem on 10. from shell, SFTP is working fine.Please help me. What can be the problem. LIB_sftp_get() { ... (0 Replies)
Discussion started by: mindtee_abhi
0 Replies

7. Solaris

Issue with Expect Script for SFTP.

Hi Experts, I am learning expect and wrote the below script for automatic sftp into a server: #!/usr/local/bin/expect -f -d spawn sftp -v test@mumux503 # logs into mumux503 as test user expect "password:" sleep 20 send "test\r"; # sending the password for test... (3 Replies)
Discussion started by: Hari_Ganesh
3 Replies

8. Shell Programming and Scripting

Help with Expect SFTP script

Hi All, Here is my Expect script, I don't get any error message when I run it. But the file never goes to other system? I also paste the output screen below. When I run the script, the script runs so fast. But when I do it manually, it takes about 10 minutes for the file to transfer. ... (1 Reply)
Discussion started by: samnyc
1 Replies

9. UNIX for Dummies Questions & Answers

sftp not working as cronjob

hi, I have a script that will automatically login into a server and get a file. it is working fine if i run it on a command line. however, when i tried to run it as a cron job, it is not working. what should i do? set timeout -1 spawn /usr/bin/sftp user1@server1 match_max 100000 expect... (3 Replies)
Discussion started by: tungaw2004
3 Replies

10. Shell Programming and Scripting

Automating SFTP with Expect

Hello all, I've written an automated SFTP script to work with the Expect command. It recently occurred to me however, that if the client side box does not have the known host entry for the server, it will not work correctly. So I have added an expect for the known host prompt, and that part... (2 Replies)
Discussion started by: sysera
2 Replies
Login or Register to Ask a Question