expect-string length problom


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users expect-string length problom
# 1  
Old 02-05-2009
expect-string length problom

hi
i am writing an expect script to automate su command, my script goes like this...

#!/usr/local/bin/expect --
set password [lindex $argv 0]
set env_var [lindex $argv 1]
spawn su UNAME [lindex $argv 0]
expect "password:"
send "$password\r"
expect "env"
send "setenv PATHVAR $env_ver\r"
expect "env"
send "echo \$PATHVAR"
expect eof

arguments i am passing is password and $PATH variable. as PATH variable will be very long in length expect is not executing properly, its failing at "send "setenv PATHVAR $env_ver\r"" and not going forward..
any help on this will be appreciated..
# 2  
Old 02-06-2009
Wrong way to go about this. Install and configure sudo and give a specific user(s) the NOPASSWD option. Here's just one thread to help you get started: https://www.unix.com/unix-advanced-ex...lp-needed.html
# 3  
Old 02-06-2009
It may be hanging as you have a typo in the variable name:

send "setenv PATHVAR $env_ver\r"

'env_ver' should be 'env_var'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Shell Programming and Scripting

String with different length

let image that we have string: QQQQQQQ:ABCDE:FFFFFF:GGGGG in second field can be 0 or 5 characters if A exist i need set variable ex: VAR=yes if B exist i need set variable ex: VAR1=yes if C exist i need set variable ex: VAR2=yes etc ... if second field is empty no variable to set if... (4 Replies)
Discussion started by: vikus
4 Replies

3. UNIX for Advanced & Expert Users

Problom Sorting

hi all, i have the test data file which is . seperated as below and i need sort it EX data: 5.4.11.3 5.4.2.2 after sort result should look like 5.4.2.2 5.4.11.3 thanks in advance. (2 Replies)
Discussion started by: sudheer157
2 Replies

4. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

5. Programming

regarding string length

Helo, I have character array of sixe 128 char filename now I have one problem that when I enter filename as nothing I got value as " " ",`\0` " . when I find this string length ( " ",`\0`) as 1(one). actually I want to make this length as zero. so what should I do (10 Replies)
Discussion started by: amitpansuria
10 Replies

6. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

7. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

8. UNIX for Dummies Questions & Answers

length of the string

Hi all, pls help me in finding the length of the given string, do we need to write a code seperately or is there any command?? pls help. (3 Replies)
Discussion started by: vasikaran
3 Replies

9. Shell Programming and Scripting

The Game Problom

weh i type in sudo shutdown nowit dose not le me shut down can i override this with out tyoing in -h :confused: my web site in the makeing is also wantin ga gane code for unix and well as a shut domne hwlp (3 Replies)
Discussion started by: thepicoman
3 Replies

10. UNIX for Dummies Questions & Answers

length of string

How one can measure the length of a string but not with the help of awk utility Can we write shell script for the same ? (2 Replies)
Discussion started by: dilipluhar
2 Replies
Login or Register to Ask a Question