expect + how to verify if dir exists and if not how to create it

2

I write expect script that login to remote machine and run there some scripts But I need also to verify the following

Verify if directory

  /var/cti/adm/APP exists

If APP not exists under adm directory , then need to create this directory and add ownership to this directory , ( as chown system )

Please advice how to check if directory exist in expect script and if not need to create this directory

example of part of my expect script

 #!/usr/bin/expect -f

 set multiPrompt {[#>$]}

 send "ssh  $LOGIN3@$IP\r"

 sleep 0.5

       expect  {

       word:  {send $PASS\r ; exp_continue } 

       expect -re $multiPrompt

       }

example how we can do it with bash

     [[ ! -d /.../..../... ]] && mkdir xxxxx

maihabunash

Posted 2014-09-02T13:38:12.930

Reputation: 479

Answers

3

set dirname /var/cti/adm/APP
if {[file exist $dirname]} {
    # check that it's a directory
    if {! [file isdirectory $dirname]} {
        puts "$dirname exists, but it's a file"
    }
} else {
    file mkdir $dirname
}

or

if {[catch {file mkdir $dirname} err opts] != 0} {
    puts $err
}

glenn jackman

Posted 2014-09-02T13:38:12.930

Reputation: 18 546