Sponsored Content
Full Discussion: expect problem
Top Forums Shell Programming and Scripting expect problem Post 302391241 by b1sh0p on Sunday 31st of January 2010 11:53:09 AM
Old 01-31-2010
expect problem

hi all, guys i have a problem in this code...

any help ?


Code:
#!/usr/bin/expect

if { $argc != 3 } {
    puts "Usage:"
    puts "$argv0 username oldpwd newpwd"
    exit
}

#set machine  [lindex $argv 0]
set username [lindex $argv 0]
set oldpwd   [lindex $argv 1]
set newpwd   [lindex $argv 2]
set completed_list " "

#-----------------------------------------
# Todas as maquinas sao setadas senhas em:
#-----------------------------------------
set machine_list {
machine1
machine2
machine3
etc
etc
}


#----------------------------------------------------
# Ping maquinas para ver qua delas esta ativa
#   Direciona para run_list
#----------------------------------------------------
foreach machine $machine_list {
    if { [ catch { exec ping -c 1 $machine  } ] == 0 } {
        lappend run_list $machine
    }
}


proc exclude_list {} {
    set count 0
    global machine_list run_list
    foreach machine $machine_list {
        incr count
        if { [ lsearch $run_list $machine ] < 0 } {
            puts "\t$count)\t$machine"
        }
    }    
    puts ""
}

proc include_list {} {
    puts "Agora vai tentar alterar a senha nas seguintes maquinas:"
    set count 0
    global machine_list run_list
    foreach machine $run_list {
        incr count
            puts "\t$count)\t$machine"
    }
    puts ""
}

proc continue_chk {} {
    global run_list
    while {1} {
        include_list
        puts -nonewline "\nVoce gostaria de continuar ou modificar lista?(y/n/m): "
        gets stdin ans
        if { 1 == [regexp {^y|Y$} $ans]  } {
            puts "yes"
            break
        } elseif { 1 == [regexp {^m|M$} $ans]  } {
            puts -nonewline "\n Entre numero para remover: "
            gets stdin ans
            set r_num [expr {$ans - 1}]
            puts $run_list
            set run_list [ lreplace $run_list $r_num $r_num ]
        } else {
            puts "no"
            exit
        }
    }
}
    
puts "Falha ao pingar as seguintes maquinas:"
exclude_list

#puts "Agora vai tentar mudar a senha nas seguintes maquinas:"
#include_list

continue_chk

foreach machine $run_list {
    set change 0
    spawn telnet $machine
    while {1} {
        expect  {
            timeout         break
            "\rlogin:"        { sleep 1
                              send "${username}\r" }
            "New password"  { send "${newpwd}\r"
                              lappend completed_list $machine
                              set change 1 }
            "new password"  { send "${newpwd}\r"
                             set change 1 }
            "Old password:" { send "${oldpwd}\r" }
            "Password:"     { send "${oldpwd}\r" }
            "\\\$"            { if {$change == 0} {
                                  send "passwd\r"
                                  set change 1
                              } else {
                                  send "exit\r" }
                            }
            "changed"       { send "exit\r" }
            "closed"        { break }
        }
        sleep 1
    }
}
    
puts " "
puts "Senha alterada com sucesso nas seguintes maquinas:"
foreach machine $completed_list {
    puts $machine
}

puts " "
puts "Senha nao foi alterada nas seguintes maquinas:"
foreach machine $machine_list {
    if { [ lsearch $completed_list $machine ] < 0 } {
        puts $machine
    }
}
exit

 

10 More Discussions You Might Find Interesting

1. AIX

problem with expect eof

hi guys i have such simple script, which i'm executing on AIX 5.3 #!/usr/local/bin/expect spawn passwd exptest set password 123 expect "*password:*" send "$password\r" expect "*password again:*" send "$password\r" expect eof the output is following: spawn passwd exptest sh:... (4 Replies)
Discussion started by: zoom
4 Replies

2. Shell Programming and Scripting

Expect script problem

Hello all you scripting Gurus, I have an expect script that gets called from an AppleScript Studio app that basically takes arguments for user name, password, and server address and then calls rsync. Everything works wonderfully, EXCEPT (there had to be one of those) if the user name starts... (4 Replies)
Discussion started by: jdyck
4 Replies

3. AIX

Problem with expect.

Hi, I am facing a strange problem while executing a script from a solaris server. This script calls another one to execute "expect" commands on some other 40 servers (all AIX 5200). I am passing username and password to the "expect" script as arguments. My problem is that it is showing the... (4 Replies)
Discussion started by: gsabarinath
4 Replies

4. UNIX for Dummies Questions & Answers

Strange expect problem

Hi I'm writing a script which calls an expect script to retrieve configuration files for network devices. I want to avoid using TFTP to transfer the configs if possible and so I'm redirecting the screen output to a text file. This is the expect script: #!/usr/local/bin/expect set... (2 Replies)
Discussion started by: Ant1815
2 Replies

5. Shell Programming and Scripting

sftp expect timeout problem

hello All, I am doing SFTP using expect. We just change our server from sun solaris 8 to sun solaris 10. The script was working good on sun solaris 8. But it is giving problem on 10. from shell, SFTP is working fine.Please help me. What can be the problem. LIB_sftp_get() { ... (0 Replies)
Discussion started by: mindtee_abhi
0 Replies

6. UNIX for Dummies Questions & Answers

Problem in Expect

Hi Im writing an expect program for automating ftp. Having trouble with mget: expect "ftp>" {send "mget *.txt\r"} expect "mget*?" {send "n\r" ; expect_continue} expect "ftp>" {send "bye\r"} But expect even on ftp prompt "n" gets sent Please help... (1 Reply)
Discussion started by: crackle1985
1 Replies

7. Shell Programming and Scripting

expect script problem

Hi, Have strange problem. When I run an expect script towards a switch, it will not work. $ ./test2 spawn ssh admin@sesafdd101 Password: Last login: Thu Dec 25 13:20:54 2008 from 172.20.96.14 ECN430/330/212 Linux, based on Wind River Linux glibc_small (standard) 2.0 Trying... (1 Reply)
Discussion started by: etxnreg
1 Replies

8. Shell Programming and Scripting

problem with expect

i have written simple expect script but it doesnt work the way that i want can someone suggest wat is the issue? #!/usr/bin/expect spawn ssh abc@abc expect "password:" send "xyz\r" expect "$" send "mkdir hello\r" #sleep 10 #exit 0 output --------------- it does not create directory... (4 Replies)
Discussion started by: bkumar82
4 Replies

9. Shell Programming and Scripting

Problem with expect script

expect { -re "(.*)NEXT PAGE(.*)" { send "\r\n" } exp_continue (0 Replies)
Discussion started by: sagar_1986
0 Replies

10. Shell Programming and Scripting

Bash expect problem

Hey there :) I have a Bash Script and I'm trying to update Roundcube, but theres a user interactive line like: bin/installto.sh /var/www/mail/rc Upgrading from 1.1.3. Do you want to continue? (y/N) I'm trying to avoid this user interaction like this: cd roundcubemail-1.2.1 >/dev/null... (5 Replies)
Discussion started by: Aeris
5 Replies
ppmtosixel(1)                                                 General Commands Manual                                                ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy