* minicom configuration file “minirc.dfl"
pu port /dev/ttyS3
pu baudrate 115200
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No
pu xonxoff No
*sample of runscript "scriptdemo"
# Alittle demonstration of the possibilities of "runscript ".
# This script can be executed by typing: "runscript scriptdemo ".
#
# Ajust the stty 's below to your system: BSD-like or SysV-like
# Linux ofcourse accepts both :-)
#
goto main
left:
print "\010 \010\010*\c "
return
right:
print "\010 *\c "
return
main:
# ! stty -echo cbreak
! stty -echo -icanon min 1
verbose off
print Demo! press 'q ' to move left, 'w ' to move right, 'ESC ' to stop.
print " *\c "
expect {
"q " gosub left
"w " gosub right
"\033 " break
}
print \nEnd of demonstration.
# ! stty icanon echo min 5
sleep 1
*
*#* example of automate minicom
http://lists.alioth.debian.org/pipermail/minicom-devel/2008/000904.html
http://blog.sina.com.cn/s/blog_5d9051c00100fmip.html
*#*--------------------------------------*#*
If you start a minicom session with the -S you can automate a minicom session with runscript. This starts two separate processes, the minicom process and the runscript process. If you want to close the minicom session when the script is finished, simply calling exit in the runscript isn't enough.
To End the minicom session you have to kill the minicom process, using the ! operator within the script to execute an external command.
The easiest method is to run
! killall minicom
This isn't recommended if you might have multiple minicom processes running. A better way is to use pkill to target the correct minicom session
! pkill -f "^minicom conf_file -S script_file$"
Where conf_file and script_file are the names of your minicom files. pkill uses a regex to kill the process that you specify.
Of course to use pkill you have to be able to generate the script file dynamically, or make sure you always call minicom with the same command when you use it. Here's how I use a bash script to generate the script and call minicom.
#!/bin/bash
minicom_profile="my_conf"
minicom_file="my_runscript"
minicom_command="minicom $minicom_profile -S $minicom_file"
pkill_command="\"^${minicom_command}$\""
cat > $minicom_file << EOF
send ""
expect {
"Press any key"
}
send "a"
! pkill -f $pkill_command
exit 0
EOF
$minicom_command
*#*--------------------------------------*#*
# Author Tim Smyth
# Module: databuoy.runscript
# Date 08/10/21
# Version 1.0
#
# runscript script to download data from the databuoy
# This script should be run within minicom
# with the command minicom -S databuoy.runscript
#
###################################################
#set the global timeout
timeout 300
verbose on
# send a carriage return first to check that the login is
# correctly displayed
sleep 5
send "^C^C^C^C^C^C^C^C"
send "\n"
send "\n"
expect {
"databuoy login:" break
timeout 60 goto panic
}
goto login
login:
send "root"
expect {
"Password:" break
timeout 60 goto panic
}
sleep 2
send "********"
expect {
"root at databuoy:~#" break
timeout 60 goto panic
}
send "cd databuoy"
expect {
"root at databuoy:~/databuoy#" break
timeout 60 goto panic
}
# issue the send command
send "sz -b -q -y outgoing.tar.gz"
expect {
"**B00"
timeout 60 goto panic
}
send "^C"
expect {
"READY: press any key to continue..."
timeout 60 goto panic
}
send "\r\r"
expect {
"root at databuoy:~/databuoy#" break
timeout 60 goto panic
}
# logout
send "exit"
sleep 5
expect {
"databuoy login:" break
timeout 60 goto panic
}
sleep 5
goto panic
#########################
# killminicom subroutine#
#########################
# kill minicom and hang up to allow future connection
killminicom:
expect {
"Enter Selection:" break
timeout 15 goto panic
}
! killall -15 minicom
#########################
# panic subroutine #
#########################
# panic kill
panic:
! killall -15 minicom
阅读(4576) | 评论(0) | 转发(0) |