Linux / UNIX Tech Support Forum
This is a discussion on Taking command line argument in expect script within the Shell scripting forums, part of the Development/Scripting category; Hi frnds, This is my first post..... I want to take IP address, username and password as command line arguments ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi frnds,
This is my first post..... I want to take IP address, username and password as command line arguments to a expect script to telnet. My script is : __________________________________________________ ____________________ ##file name is : script.sh #!/bin/bash #!/usr/bin/expect -- ##/usr/bin/expect is the directory where expect was installed log_user 0 ##this command is used to hide the conversationn between the script and the other machine set address [lrange $argv 0 0] ##assign the first passed parameter while calling the script to $address set username [lrange $argv 1 1] ##assign the 2nd passed parameter while calling the script to $username set password [lrange $argv 2 2] ##assign the 3rd passed parameter while calling the script to $password spawn telnet ${address} ##start the telnet session to machine with IP=$address ##start conversation with the machine: expect "login:" send -- "$username\r" expect "Password:" send -- "$password\r" expect "$ " send --"exit\r" __________________________________________________ ____________________ im running script as: expect script.sh 10.1.101.80 root password but it is showing the error : can't read "address": no such variable while executing "set address [lrange $argv 0 0] (file "script.sh" line 6) __________________________________________________ ____________________ please help me.....I hv expect and Tcl packages installed on my machine (OS is REL-4) |
| Sponsored Links | ||
|
|
|
||||
|
Remove #!/bin/bash and try again!
__________________
Vivek Gite Linux Evangelist |
|
|||
|
# works as a comment only if it's the first character on the line, so basically your comments are messing you script.Move each and every one of them to their own line and it should work(or at least spit a different error).
|
|
|||
|
Thanks for your help fcojocaru ...its working now.
I hv one more issue: I want to store the logs for some commands which i am executing in expect script, to a txt file. I want to check whether the command was wuccessful or it was failed. Log file format: command <3> - successful command <8> - failed ................................... command <27> - failed How to do this ...plz help. |
|
|||
|
This is trickier; Check the manpage of expect to see how to make a simple decision structure ( if - then - else ) , and check specifically for the log_file directive. There is no simple way to check the $? like in bash , but rather check the output of the executed command ( telnet in your case ).
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to open and read a file that is supplied as a command line arg | blingbling | Shell scripting | 3 | 31-03-2009 10:54 AM |
| Shell script to count number of lines in file specified by the second command-line | seaman77 | Shell scripting | 1 | 16-03-2009 07:46 PM |
| expect script hangs | antzjos | Shell scripting | 0 | 22-05-2008 06:37 PM |
| Expect and tcl - manymaint.exp script | Intelligen | Shell scripting | 11 | 21-11-2007 02:48 PM |
| Command line remote access | angelus_kit | Networking, Firewalls and Security | 7 | 05-09-2007 06:30 PM |