LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-08-2019, 05:03 AM   #1
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 976

Rep: Reputation: 47
cron + expect


"#!/usr/bin/expect -f..." script doesnt work in cron.
I use it for telnet.
I have googled it and others have the same problem, but couldnt find solution.

thanks.

edit2:

nope it dont work, breaks at:
spawn /usr/bin/telnet <ipadress>

Last edited by qrange; 07-08-2019 at 06:31 AM.
 
Old 07-08-2019, 06:43 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,175

Rep: Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832
Quote:
Originally Posted by qrange View Post
spawn /usr/bin/telnet <ipadress>
My guess is that this doesn't work because telnet expects (no pun intended) a tty, and cron doesn't provide one.

It would help if you shared the entire expect script and also told us what the script is supposed to achieve.
 
Old 07-09-2019, 06:54 AM   #3
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 976

Original Poster
Rep: Reputation: 47
I've found solution here:

http://www.wellho.net/forum/The-Tcl-...with-cron.html

that guy had the exact same problem (eof) and solved it by removing 'expect_after timeout'.
it works now but is there a way to keep the timeout?

edit:
solved completely by putting command 'expect_after timeout' at end of script, like this:
Code:
#!/usr/bin/expect

# exp_internal 1

# unset -nocomplain ::env(SSH_AUTH_SOCK)   ;# This one is session-bound anyway
# puts[list array set ::env [array get ::env]]

# set env(PATH) "/home/dj/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"

set verbose 0
set env(TERM) vt100
set env(SHELL) /bin/bash
set env(HOME) /home/dj

#If it all goes pear shaped the script will timeout after 5 seconds.
set timeout 5
#assigned to the variable name
set name [lindex $argv 0]
#assigned to the variable password
set password "eqz0fsRMBsnjihy"
#This spawns the telnet program and connects it to the variable name
spawn /usr/bin/telnet $name 
#The script expects Password
expect "Password: "
#The script sends the password variable
send "$password\n"
send "sys diag\n"
send "show all\n"
send "ip status\n"
send "ip route status\n"
send "ip arp status\n"
send "ip ifconfig\n"
send "wan adsl linedata near\n"
send "wan adsl linedata far\n"
send "wan adsl txgain\n"
send "wan adsl farituid\n"
send "wan adsl nearituid\n"
send "sys countrycode\n"
send "sys atsh\n"
send "sys upnp display\n"
send "show wan adsl annex\n"
send "show wan adsl opmode\n"
send "wan adsl txfilter\n"
send "wan adsl targetnoise\n"
send "exit\n"

# send "sys view autoexec.net\n\n"

#This hands control of the keyboard over to you (Nice expect feature!)
# interact
expect_after timeout {puts "Timeout, exiting....";exit 0}
expect eof
exit

# set reboot
# sys diag
# sys view autoexec.net
# sys log disp  y/n?
# send "sys display\n"
# iskljuci wifi:  rtwlan disableap

Last edited by qrange; 07-09-2019 at 07:14 AM.
 
  


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
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration