LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   expect (https://www.linuxquestions.org/questions/programming-9/expect-75916/)

sk8guitar 07-25-2003 03:27 PM

expect
 
hey, i am trying to get the username from the system in expect

but the $ is a special character reserved for expect variables. so going

set username "[exec echo $USER]"

of course gives me errors. does anyone know the correct way to do this?

david_ross 07-26-2003 11:27 AM

Rather than using $user why not use the "whoami" command.
set username "[exec whoami]"

coolest 07-29-2003 04:24 AM

hi Ihave a problem in my expect script

#!/usr/local/bin/expect
set User "updates"
set Password "updates"
set Prompt "ftp>"
set Host "ftp.freedomain.com"
set Yes "prompt"
set Local "/home/ryan/parsedlogs/"
#set Yehey "mput yehey*"
################################################# Connect to FTP
spawn "/home/ryan/parsedlogs"
spawn ftp $Host
################################################# Username
expect "Name (ftp.freedomain.com:ryan):"
send "$User\n"
################################################# Password
expect "Password:"
send "$Password\n"
################################################# Enter Command Option of FTP
#expect "$Prompt"
#send "passive\n"
expect "$Prompt"
send "$Yes\n"
expect "$Prompt"
send "hash\n"
################################################# Upload yeheylogs files
expect "$Prompt\n"
send "mput $Local*.*\r"
expect "$Prompt"
send "ls -al\n"
expect "$Prompt\n"
send "bye\n"

when i run this script it says
spawn /home/ryan/parsedlogs
couldn't execute "/home/ryan/parsedlogs": permission denied
while executing
"spawn "/home/ryan/parsedlogs""
(file "/home/ryan/scripts/ftptest.exp" line 10)

x2000koh 07-29-2003 09:24 PM

sk8guitar,
You can use (id -u) try to look at man id which can return you the user.

at your comand type id, you see your id, uid gid and etc.

try to modify it at your own preference.

hope it help

x2000koh


All times are GMT -5. The time now is 02:47 PM.