LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices

Reply
 
Search this Thread
Old 08-28-2013, 10:08 AM   #1
gbisschops
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Rep: Reputation: Disabled
expect : creating a folder with a timestamp in a send command


Hello,

I'm working on an AIX 5.3 mainframe. I have to automatically send files with sftp.

I choose the expect way, here is my code :

Code:
#!/usr/bin/expect -d -f
#spawn /usr/bin/sftp -b sftpbatch user@host
#set mydate `date +%Y%m%d%H%M%S`
cd /imxapp4/impr_files/pcltosend
spawn /usr/bin/sftp user@host
match_max 100000
expect "*ass*"
send -- "mypassword\n"
expect "*Connected*"
send -- "lcd /test\n"
sleep 1
send -- "mkdir date +%Y%m%d%H%M%S\n"
sleep 1
send -- "PUT *\n"
expect eof

output result for the mkdir part :
send: sending "mkdir date +%Y%m%d%H%M%S\n" to { exp4 }

This is simply creating a "date" folder

You can see my first attempt :

Code:
#set my_command `date +%Y%m%d%H%M%S`
...
send -- "mkdir mydate\n"
output :
...
executing commands from command file ./test_expect.sh
wrong # args: should be "set varName ?newValue?"
while executing
"set mydate `date +%Y%m%d%H%M%S`"
(file "./test_expect.sh" line 3)

Do you have an idea how I can do this ? With another shell script without the expect stuff it is working as expected ?

Thanks in advance,

Greg.
 
Old 08-29-2013, 03:33 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,599

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Something like this?
Code:
#!/usr/local/bin/bash

MYDATE=$(date +%Y%m%d%H%M%S)

expect -f - $MYDATE <<"DONE"
set mydate [lrange $argv 0 0]
spawn /usr/bin/sftp user@localhost
match_max 100000
expect "*ass*"
send -- "passvoid\n"
expect "*Connected*"
send -- "cd /tmp\n"
sleep 1
send -- "mkdir date-$mydate\n"
sleep 1
send -- "QUIT\n"
expect eof
DONE
 
Old 08-29-2013, 04:04 AM   #3
gbisschops
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for your help.

I don't have bash shell installed I think :

Current available shells:
/bin/sh
/bin/bsh
/bin/csh
/bin/ksh
/bin/tsh
/bin/ksh93
/usr/bin/sh
/usr/bin/bsh
/usr/bin/csh
/usr/bin/ksh
/usr/bin/tsh
/usr/bin/ksh93
/usr/bin/rksh
/usr/bin/rksh93
/usr/sbin/uucp/uucico
/usr/sbin/sliplogin
/usr/sbin/snappd

I replaced the first line with #!/usr/bin/bsh
Then I have this :

./sftp_send.sh: syntax error at line 3: `MYDATE=$' unexpected

?
 
1 members found this post helpful.
Old 08-29-2013, 04:40 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,599

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
It should work with the default AIX shell (/bin/sh)
 
Old 08-29-2013, 05:06 AM   #5
gbisschops
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi thanks you a lot this made my day

Just one more thing, do you know how I can log the expect stuff in a file ?
I need a logfile to proof I've uploaded the files
 
Old 08-29-2013, 05:22 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,599

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
With redirection?

Code:
#!/bin/sh

MYDATE=$(date +%Y%m%d%H%M%S)

exec >/tmp/ftp.$MYDATE.log 2>&1

expect -f - $MYDATE <<"DONE"
...
then later:
Code:
$ cat /tmp/ftp.20130829122051.log 
spawn /usr/bin/sftp user@localhost
user@localhost's password: 
Connected to localhost.
cd /tmp
sftp> cd /tmp
sftp> mkdir date-20130829122051
sftp> QUIT
 
Old 08-29-2013, 06:58 AM   #7
gbisschops
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you again it is perfect
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 04:29 AM
TCL - Expect -- IF results Are different Then send a command ritztech Programming 1 12-11-2010 04:55 PM
expect - can't use ">>" (append) in send command? dbdbdb Programming 2 12-05-2009 09:36 AM
expect says it cant send the string to the spawned command exceed1 Programming 0 01-17-2009 06:51 AM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 04:38 PM


All times are GMT -5. The time now is 06:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration