1

I have a TCL expect script that runs a scp command for uploading a config file to my DNS server:

#!/usr/bin/expect -f

set config "~/dnsmasq.conf"

spawn /usr/bin/scp "$config" root@192.168.1.1:/etc/dnsmasq.conf

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$password\r"
        expect {
            -re ".*denied.*" {
                exit 7
            }
        }
    }
}

I would like to return a specific error code if the scp utility can not be found. Currently the script exits with a status of 1. If the script exits with a status of 7, I can handle that because I know it's an access denied error. The error that shows up in the Apache log is:

couldn't execute "/usr/bin/scp": no such file or directory
    while executing
"spawn /usr/bin/scp "$config" root@192.168.1.1:/etc/dnsmasq.conf"

How can I return an error code of 5 or something at this point?

1 Answer 1

3

Best way to do it would be to check if it exists and is executable:

if { ! ([file exists /usr/bin/scp] && [file executable /usr/bin/scp])} {
    puts stderr "/usr/bin/scp does not exist or is not executable"
    exit 7
}

spawn /usr/bin/scp ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.