1

i use a cronjob to execute a filetransfer to a host and then telnet into the host and pipe some commands into it.

HOST=somehost
USER=postgres
PASSWD=blabla
ftp -n -v $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put schema_1.sql
put schema_2.sql
quit
END_SCRIPT

(sleep 20;
 echo "blabla2";
 sleep 5;
 echo "psql -d cb3db -f schema_1.sql";
 echo "psql -d cb3db -f schema_2.sql";
 echo "rm *.sql";
 echo "exit;"
 ) | telnet -l postgres somehost
echo "END OF REMOTE SCRIPT" ||:

it seems whatever I pipe/echo into the session gets executed parallel, it happens the exit is executed before the sql finished executing. I tried to put sleeps before the exit command, but thats rather a guessing game.

I know this approach is certainly not the most secure because of passwords,etc. So if there is a safer and securer way to do the job let me know.

Thanks for any hints

3 Answers 3

4

"expect" is the usual way to script such interactions.

http://en.wikipedia.org/wiki/Expect

0

+1 for expect.

However, if you're like me, you'll find tcl (expect's native language) extremely painful.

If you dig down in to the wikipedia article, you'll find that there are perl and python (and certainly other) bindings for expect that let you do all the interactive things you need with much less code pain.

Best of luck.

0

Perl also has IPC::Run which I'm beginning to use after having used Expect (in Tcl and perl) quite a lot. My IPC::Run based code tends to be shorter and easier to read when I'm done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .