- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Expect script on crontab
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2004 06:38 PM
12-07-2004 06:38 PM
I have an expect script called sftp to transfer using SFTP below :
[root@prod:/root]
# more sftp
#!/usr/local/bin/expect
# Initialisation
set authFile "/home/ap1030/transfer/.password"
# Check the authorisation file exists
if {![file exists $authFile]} { ;# Does file exist
send_user "$authFile does not exist; aborting\n"
exit 1
}
set fileFD [open $authFile r] ;# Open the auth file
gets $fileFD authLine ;# Read in 1 line to authLine
close $fileFD
# Transfer file(s)
spawn /opt/openssh/bin/sftp -b /home/ap1030/transfer/batchFile importve@www.importve.com
expect "password:"
send "$authLine\n";
interact
When I run this script manually from command line, it was running fine. But when I put on crontab, it was NOT working. I believe this is related to "interact" command on the last line. How can I make the script running from crontab? Pls help. High score will be give.
Below is my crontab entry and the log file. .
05 15 * * * /usr/local/bin/expect -f /home/ap1030/transfer/sftp > /tmp/sftp 2>1&
[importve@prod:/home/ap1030/transfer]
$ more /tmp/sftp
spawn /opt/openssh/bin/sftp -b /home/ap1030/transfer/batchFile importve@www.importve.com
Connecting to www.importve.com...
importve@www.importve.com's password:
Thanks and Best Regards,
Dewa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2004 07:38 PM
12-07-2004 07:38 PM
Solutionhttp://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=757938
I see you have suppressed the shell part. Expect doesn't seem to match your string. This make me insist on the way of environment problems.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2004 08:02 PM
12-07-2004 08:02 PM
Re: Expect script on crontab
Thanks alot for your help. I tried it, but the script still can not run well. I configured it as below.
[importve@prod:/home/ap1030/transfer]
$ crontab -l
57 16 * * * /home/ap1030/transfer/run_sftp > /tmp/sftp 2>1&
[importve@sihp8026:/home/ap1030/transfer]
$ more run_sftp
. /home/importve/.profile
cd /home/ap1030/transfer
./sftp
[importve@sihp8026:/home/ap1030/transfer]
$ more /tmp/sftp
spawn /opt/openssh/bin/sftp -b /home/ap1030/transfer/batchFile importve@www.importve.com
Connecting to www.importve.com...
importve@www.importve.com's password:
[importve@sihp8026:/home/ap1030/transfer]
$ ll
total 8
-rw-r--r-- 1 importve sys 56 Dec 2 14:44 batchFile
-rwx------ 1 importve sys 117 Dec 8 16:54 run_sftp
-rwx------ 1 importve sys 520 Dec 8 16:55 sftp
-rw-r--r-- 1 importve sys 13 Dec 2 14:43 test_sihp8026
I got this link http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=13&t=000741 that related to my issue. It mentioned that the problem with the command "interact" in expect.
Any idea, pls help me.
Thanks and Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2004 08:46 PM
12-07-2004 08:46 PM
Re: Expect script on crontab
05 15 * * * su - root -c "/usr/local/bin/expect -f /home/ap1030/transfer/sftp > /tmp/sftp 2>1&"
(or use any other user if you don't want to launch with root)
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2004 09:43 PM
12-07-2004 09:43 PM
Re: Expect script on crontab
Thanks. I tried it below. But still can not resolve the issue.
[root@prod:/home/ap1030/transfer]
# more /tmp/sftp
spawn /opt/openssh/bin/sftp -b /home/ap1030/transfer/batchFile importve@www.importve.com
Connecting to www.importve.com...
importve@www.importve.com's password:
[root@prod:/home/ap1030/transfer]
# crontab -l|grep sftp
33 18 * * * su - root -c "/usr/local/bin/expect -f /home/ap1030/transfer/sftp > /tmp/sftp 2>1&"
It always stuck after running command "interact" on the last line.
I got the information about "interact" command in expect as below :
"Interact is an Expect command that transfers control from the script to the user. When this command is executed, Expect stops reading commands from the script and instead begins reading from the keyboard."
Thanks and Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2004 01:13 AM
12-08-2004 01:13 AM
Re: Expect script on crontab
I imagine that, by using interact, you want expect to read the file specified with -b. Have you tried replacing "-b" with "<", in order for the file to become input ? To try this, keep interact and only modify -b option.
Other way is to find an expect command that would use file provided by -b as interact uses input.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)