I have the following expect script sitting on a Linux box.
===
Code:
#!/usr/bin/expect -f
#
# backup.expect
#
# Expect script to backup a firewall via a SSH session
#
#
set firewall [ lrange $argv 0 0 ]
set username [ lrange $argv 1 1 ]
set password [ lrange $argv 2 2 ]
set prompt [ lrange $argv 3 3 ]
set filename [ lrange $argv 3 3 ]
match_max 50000
spawn ssh -l $username $firewall
expect "yes/no" { send "yes\r" }
expect "assword:"
send "$password\r"
expect -timeout 10 "word>"
set output [open "$filename" "w"]
set running 1
send "show config running\r"
expect "\n"
expect "\[K"
while { $running > 0 } {
expect {
"\n" { puts -nonewline $output "$expect_out(buffer)" }
"lines *-* " { send " " }
"assword:" { set running 0 }
eof { set running 0 }
timeout { set running 0 }
}
}
send "exit\r"
===
Its entire purpose is to login to a firewall device, do a "show config running", collect the output into a file. When i run it manually, it works flawlessly - but when it is executed VIA crontab i get the following:
===
Code:
Running commands on 10.0.0.1...
spawn ssh -l xxx 10.0.0.1
Password:
Last login: Sun Apr 1 00:26:41 2012 from xxx
xxx@10.0.0.1> show
xxx@10.0.0.1> show config
xxx@10.0.0.1> show config running
WARNING: terminal is not fully functional
- (press RETURN)Finished running commands on xxx...
===
and when i run the script manually i get this:
===
Code:
Password:
Last login: Sun Apr 8 05:27:10 2012 from xxx
xxx@10.0.0.1> show config running
config { full config correctly displayed...
===
So my question is, why does crontab output
Code:
xxx@10.0.0.1> show
xxx@10.0.0.1> show config
xxx@10.0.0.1> show config running
when manualy it correctly inputs as per my script....:
Code:
xxx@10.0.0.1> show config running
Also, what could "WARNING: terminal is not fully functional" possibly mean? Is my SSH session spawned incorrectly when run VIA cron? By the way both the crontab and manual execution of the script is done through bash, and the same user...... any help is appreciated...... thanks!
-Alagondar
Last edited by Franklin52; 04-08-2012 at 06:33 AM..
Reason: Please use code tags for data and code samples, thank you
Hi All,
Using Expect script when I run it manually it works. But when I put the entry in crontab, the job is still running after 15 hours. The script was created as root. I don't think it's a permission issue. Any idea?
This is what I have under root crontab...
00 18 * * 1-5... (4 Replies)
Hi All,
I have an expect script called sftp to transfer using SFTP below :
# more sftp
#!/usr/local/bin/expect
# Initialisation
set authFile "/home/ap1030/transfer/.password"
# Check the authorisation file exists
if {!} { ;# Does file exist
send_user "$authFile does not exist;... (6 Replies)
#!/bin/bash
#
# RAP configuration script
#
# Usage: ./rap.sh
#
# Requires: expect, tcl
#
# Script expects to find a file called rap.csv located in the same directory as the script. If the file is placed
# in a different directory, modify the custom entries section to specify the absolute... (8 Replies)
Shell Scipt: temp.sh
su - <$username>
expect pass.exp
Expect script: pass.exp
#!/usr/bin/expect -f
# Login
#######################
expect "Password: " send "<$password>\r"
it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Hi All,
I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below:
#cat /var/log/testexp.log
spawn minicom -C /var/log/minicom1.log
No cursor motion capability (cm)
AT+COPS=?
I am new in scripting, together... (1 Reply)
Hi All,
I run the scp command in shell prompt without issue, but when on expect script as below:
#!/usr/bin/expect
spawn scp /var/spool/sms/failed.tar.gz abc@10.10.12.2:/home/abc
expect "abc@10.10.12.2's password: "
send "abcfef\r"
exit 0
It looks not working at all and the... (3 Replies)
I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows:
#!/bin/bash
HOST=$1
/usr/bin/expect -c "
spawn ssh -i /root/.ssh/id_rsa root@$HOST
expect -exact "Enter... (3 Replies)
Hi,
I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (6 Replies)
Hi,
I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)