![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| within shell script send expect and if else | mnmonu | Shell Programming and Scripting | 1 | 04-20-2009 06:41 AM |
| Using Expect results in a Shell script | kaltekar | Shell Programming and Scripting | 2 | 10-17-2008 10:08 AM |
| Using expect script in a shell script or vice versa | nua7 | Shell Programming and Scripting | 0 | 07-18-2008 08:16 AM |
| Need help with Expect and Shell script | tonan | Shell Programming and Scripting | 1 | 04-10-2008 11:45 PM |
| Password changing in a Script (shell and expect) | chellam | Shell Programming and Scripting | 1 | 08-15-2006 12:12 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
within shell script send expect and if else
Hi,
I have written one shell script , using that i am able to connect to remote machine but i have to #!/usr/bin/expect -f set address [lindex $argv 0] set username [lindex $argv 1] set password [lindex $argv 2] set OOLpath [lindex $argv 3] set dbusername [lindex $argv 4] set dbpasswd [lindex $argv 5] set tnsname [lindex $argv 6] set recdbusername [lindex $argv 7] set recdbpasswd [lindex $argv 8] set rectnsname [lindex $argv 9] spawn ssh ${username}@${address} expect "${username}@${address}'s password:" send -- "${password}\r" expect "$ " send -- "cd ${OOLpath}\r" expect "$ " send -- "cd Client\conf\r" ##########IF-ELSE Block expect eof but I need to check if one file(named parfile) is exist or not and if exist then change some parameter value cat parfile dbtnsname = clienttns dbuserid = scott dbpasswd = tiger and if not exist then copy from some directory and then change parameter dbuserid,dbpasswd value. Please Please help me.Thanks in advance. |
|
|||||
|
Hi. Here is an expect script that connects and then checks for a file t2. Perhaps this will help until someone more knowledgeable stops by: Code:
#!/usr/bin/expect --
# @(#) e4 Demonstrate running commands on remote computer with expect.
# Identify local computer, version of expect.
puts " Local computer is [eval exec uname -n]"
puts " Version of expect is [exp_version]."
puts ""
# Read login-name, computer-name, password from file.
set file "data1"
if { ! [file exists $file] } {
puts " File $file not found -- exiting."
exit 1
}
set input [open $file "r"]
set line [gets $input]
set list [split $line]
set login [lindex $list 0]
set box [lindex $list 1]
set password [lindex $list 2]
puts " login is $login, intended remote computer is $box"
set timeout 10
send_user " spawning: ssh $login@$box\n"
spawn ssh $login@$box
expect \[pP]assword:*
send "$password\r"
# send_user "(Got string Password*, sent password $password.)\n"
expect *$box*
# send "ls\r"
send {
bash <<EOF
echo " Hi from a here document on computer $(uname -n)."
if [ ! -f t2 ]
then
echo " There is no file t2, creating it."
touch t2
else
echo " File t2 exists, using it."
fi
ls -l t2
rm t2
EOF
}
expect *$box*
send "exit\r"
expect "logout*"
Producing: Code:
% ./e4 Local computer is leap Version of expect is 5.42.1. login is vanilla, intended remote computer is vm-lenny spawning: ssh vanilla@vm-lenny spawn ssh vanilla@vm-lenny vanilla@vm-lenny's password: Linux vm-lenny 2.6.26-2-686 #1 SMP Thu Mar 26 01:08:11 UTC 2009 i686 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Thu Apr 23 09:37:28 2009 from leap bash <<EOF echo " Hi from a here document on computer $(uname -n)." if [ ! -f t2 ] then echo " There is no file t2, creating it." touch t2 else echo " File t2 exists, using it." fi ls -l t2 rm t2 EOF vanilla@vm-lenny:~$ vanilla@vm-lenny:~$ bash <<EOF > echo " Hi from a here document on computer $(uname -n)." > if [ ! -f t2 ] > then > echo " There is no file t2, creating it." > touch t2 > else > echo " File t2 exists, using it." > fi > ls -l t2 > rm t2 > EOF Hi from a here document on computer vm-lenny. There is no file t2, creating it. -rw-r--r-- 1 vanilla vanilla 0 2009-04-23 10:13 t2 vanilla@vm-lenny:~$ exit logout If you are going to use expect extensively, I suggest the book below ... cheers, drl Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|